mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-01 04:07:53 +08:00
Load the journal list after onboarding
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:journal/state_container.dart';
|
||||||
import 'package:journal/screens/home_screen.dart';
|
import 'package:journal/screens/home_screen.dart';
|
||||||
import 'package:journal/screens/onboarding_screens.dart';
|
import 'package:journal/screens/onboarding_screens.dart';
|
||||||
|
|
||||||
@ -12,8 +13,12 @@ class JournalApp extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var onBoardingDone = false;
|
final stateContainer = StateContainer.of(context);
|
||||||
var home = onBoardingDone ? new HomeScreen() : new OnBoardingScreen();
|
|
||||||
|
var onBoardingDone = stateContainer.appState.onBoardingCompleted;
|
||||||
|
var home = onBoardingDone
|
||||||
|
? new HomeScreen()
|
||||||
|
: new OnBoardingScreen(stateContainer.completeOnBoarding);
|
||||||
|
|
||||||
return new MaterialApp(
|
return new MaterialApp(
|
||||||
title: 'Journal',
|
title: 'Journal',
|
||||||
|
13
lib/appstate.dart
Normal file
13
lib/appstate.dart
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import 'package:journal/note.dart';
|
||||||
|
|
||||||
|
class AppState {
|
||||||
|
bool onBoardingCompleted;
|
||||||
|
bool isLoadingFromDisk;
|
||||||
|
List<Note> notes;
|
||||||
|
|
||||||
|
AppState({
|
||||||
|
this.onBoardingCompleted = false,
|
||||||
|
this.isLoadingFromDisk = false,
|
||||||
|
this.notes = const [],
|
||||||
|
});
|
||||||
|
}
|
@ -60,23 +60,3 @@ class Note implements Comparable {
|
|||||||
return created.compareTo(other.created);
|
return created.compareTo(other.created);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AppState {
|
|
||||||
bool isLoadingFromDisk;
|
|
||||||
bool localStateModified;
|
|
||||||
|
|
||||||
bool isLoadingRemoteState;
|
|
||||||
bool remoteStateModified;
|
|
||||||
|
|
||||||
List<Note> notes;
|
|
||||||
|
|
||||||
AppState({
|
|
||||||
this.isLoadingFromDisk = false,
|
|
||||||
this.localStateModified = false,
|
|
||||||
this.isLoadingRemoteState = false,
|
|
||||||
this.remoteStateModified = false,
|
|
||||||
this.notes = const [],
|
|
||||||
});
|
|
||||||
|
|
||||||
//factory AppState.loading() => AppState(isLoading: true);
|
|
||||||
}
|
|
||||||
|
@ -4,6 +4,10 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||||||
import 'package:journal/storage/git.dart';
|
import 'package:journal/storage/git.dart';
|
||||||
|
|
||||||
class OnBoardingScreen extends StatelessWidget {
|
class OnBoardingScreen extends StatelessWidget {
|
||||||
|
final Function onBoardingCompletedFunction;
|
||||||
|
|
||||||
|
OnBoardingScreen(this.onBoardingCompletedFunction);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var pageController = PageController();
|
var pageController = PageController();
|
||||||
@ -26,7 +30,9 @@ class OnBoardingScreen extends StatelessWidget {
|
|||||||
curve: Curves.easeIn,
|
curve: Curves.easeIn,
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
OnBoardingGitClone(),
|
OnBoardingGitClone(
|
||||||
|
doneFunction: this.onBoardingCompletedFunction,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -151,17 +157,25 @@ class OnBoardingSshKeyState extends State<OnBoardingSshKey> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class OnBoardingGitClone extends StatefulWidget {
|
class OnBoardingGitClone extends StatefulWidget {
|
||||||
|
final Function doneFunction;
|
||||||
|
|
||||||
|
OnBoardingGitClone({@required this.doneFunction});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
OnBoardingGitCloneState createState() {
|
OnBoardingGitCloneState createState() {
|
||||||
return new OnBoardingGitCloneState();
|
return new OnBoardingGitCloneState(doneFunction: this.doneFunction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class OnBoardingGitCloneState extends State<OnBoardingGitClone> {
|
class OnBoardingGitCloneState extends State<OnBoardingGitClone> {
|
||||||
|
final Function doneFunction;
|
||||||
String errorMessage = "";
|
String errorMessage = "";
|
||||||
|
|
||||||
|
OnBoardingGitCloneState({@required this.doneFunction});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
super.initState();
|
||||||
_initStateAsync();
|
_initStateAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,6 +188,8 @@ class OnBoardingGitCloneState extends State<OnBoardingGitClone> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
errorMessage = error;
|
errorMessage = error;
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
doneFunction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,7 +207,7 @@ class OnBoardingGitCloneState extends State<OnBoardingGitClone> {
|
|||||||
value: null,
|
value: null,
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
} else {
|
} else if (this.errorMessage.isNotEmpty) {
|
||||||
children = <Widget>[
|
children = <Widget>[
|
||||||
Text(
|
Text(
|
||||||
'Failed',
|
'Failed',
|
||||||
|
@ -6,8 +6,8 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
|
import 'package:journal/appstate.dart';
|
||||||
import 'package:journal/note.dart';
|
import 'package:journal/note.dart';
|
||||||
import 'package:journal/storage/serializers.dart';
|
|
||||||
import 'package:journal/storage/notes_repository.dart';
|
import 'package:journal/storage/notes_repository.dart';
|
||||||
import 'package:journal/storage/git_storage.dart';
|
import 'package:journal/storage/git_storage.dart';
|
||||||
import 'package:journal/storage/git.dart';
|
import 'package:journal/storage/git.dart';
|
||||||
@ -52,8 +52,10 @@ class StateContainerState extends State<StateContainer> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
_loadNotesFromDisk();
|
if (appState.onBoardingCompleted) {
|
||||||
_syncNotes();
|
_loadNotesFromDisk();
|
||||||
|
_syncNotes();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _loadNotesFromDisk() {
|
void _loadNotesFromDisk() {
|
||||||
@ -117,6 +119,15 @@ class StateContainerState extends State<StateContainer> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void completeOnBoarding() {
|
||||||
|
setState(() {
|
||||||
|
this.appState.onBoardingCompleted = true;
|
||||||
|
|
||||||
|
_loadNotesFromDisk();
|
||||||
|
_syncNotes();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return _InheritedStateContainer(
|
return _InheritedStateContainer(
|
||||||
|
Reference in New Issue
Block a user