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