Add a very basic onBoardingScreen

This commit is contained in:
Vishesh Handa
2019-02-14 01:43:34 +01:00
parent 6fea27e0ca
commit c819f49afe
5 changed files with 101 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import 'package:journal/state_container.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'screens/githostsetup_screens.dart'; import 'screens/githostsetup_screens.dart';
import 'screens/onboarding_screens.dart';
class JournalApp extends StatelessWidget { class JournalApp extends StatelessWidget {
static FirebaseAnalytics analytics = FirebaseAnalytics(); static FirebaseAnalytics analytics = FirebaseAnalytics();
@ -24,9 +25,11 @@ class JournalApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var stateContainer = StateContainer.of(context); var stateContainer = StateContainer.of(context);
var onCompleted = () {
stateContainer.completeGitHostSetup(); var initialRoute = '/';
}; if (!stateContainer.appState.onBoardingCompleted) {
initialRoute = '/onBoarding';
}
return MaterialApp( return MaterialApp(
title: 'GitJournal', title: 'GitJournal',
@ -38,11 +41,14 @@ class JournalApp extends StatelessWidget {
accentColor: Color(0xff6d4c41), accentColor: Color(0xff6d4c41),
), ),
navigatorObservers: <NavigatorObserver>[JournalApp.observer], navigatorObservers: <NavigatorObserver>[JournalApp.observer],
initialRoute: '/', initialRoute: initialRoute,
routes: { routes: {
'/': (context) => HomeScreen(), '/': (context) => HomeScreen(),
'/settings': (context) => SettingsScreen(), '/settings': (context) => SettingsScreen(),
'/setupRemoteGit': (context) => GitHostSetupScreen(onCompleted), '/setupRemoteGit': (context) =>
GitHostSetupScreen(stateContainer.completeGitHostSetup),
'/onBoarding': (context) =>
OnBoardingScreen(stateContainer.completeOnBoarding),
}, },
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
//debugShowMaterialGrid: true, //debugShowMaterialGrid: true,

View File

@ -10,6 +10,7 @@ class AppState {
bool remoteGitRepoConfigured = false; bool remoteGitRepoConfigured = false;
bool hasJournalEntries = false; bool hasJournalEntries = false;
bool onBoardingCompleted = false;
// FIXME: Make final // FIXME: Make final
String gitBaseDirectory = ""; String gitBaseDirectory = "";

View File

@ -38,6 +38,7 @@ Future runJournalApp() async {
pref.getBool("remoteGitRepoConfigured") ?? false; pref.getBool("remoteGitRepoConfigured") ?? false;
var localGitRepoPath = pref.getString("localGitRepoPath") ?? ""; var localGitRepoPath = pref.getString("localGitRepoPath") ?? "";
var remoteGitRepoPath = pref.getString("remoteGitRepoPath") ?? ""; var remoteGitRepoPath = pref.getString("remoteGitRepoPath") ?? "";
var onBoardingCompleted = pref.getBool("onBoardingCompleted") ?? false;
if (JournalApp.isInDebugMode) { if (JournalApp.isInDebugMode) {
if (JournalApp.analytics.android != null) { if (JournalApp.analytics.android != null) {
@ -66,6 +67,7 @@ Future runJournalApp() async {
localGitRepoPath: localGitRepoPath, localGitRepoPath: localGitRepoPath,
remoteGitRepoPath: remoteGitRepoPath, remoteGitRepoPath: remoteGitRepoPath,
gitBaseDirectory: dir.path, gitBaseDirectory: dir.path,
onBoardingCompleted: onBoardingCompleted,
child: JournalApp(), child: JournalApp(),
)); ));
} }

View File

@ -0,0 +1,76 @@
import 'package:dots_indicator/dots_indicator.dart';
import 'package:flutter/material.dart';
import 'githostsetup_button.dart';
class OnBoardingScreen extends StatefulWidget {
final Function onCompletedFunction;
OnBoardingScreen(this.onCompletedFunction);
@override
OnBoardingScreenState createState() {
return OnBoardingScreenState();
}
}
class OnBoardingScreenState extends State<OnBoardingScreen> {
var pageController = PageController();
int _currentPageIndex = 0;
Widget _buildPage(String text) {
return Column(
children: <Widget>[
Text(text),
GitHostSetupButton(
text: 'Take me to the App',
onPressed: () {
widget.onCompletedFunction();
Navigator.pop(context);
Navigator.pushNamed(context, "/");
},
),
],
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
);
}
@override
Widget build(BuildContext context) {
var pages = <Widget>[
_buildPage("Page 1"),
_buildPage("Page 2"),
_buildPage("Page 3"),
];
var pageView = PageView(
controller: pageController,
children: pages,
onPageChanged: (int pageNum) {
setState(() {
_currentPageIndex = pageNum;
});
},
);
return Scaffold(
body: Container(
width: double.infinity,
height: double.infinity,
child: Stack(
alignment: FractionalOffset.bottomCenter,
children: <Widget>[
pageView,
DotsIndicator(
numberOfDot: pages.length,
position: _currentPageIndex,
dotActiveColor: Theme.of(context).primaryColorDark,
)
],
),
padding: EdgeInsets.all(16.0),
),
);
}
}

View File

@ -19,6 +19,7 @@ class StateContainer extends StatefulWidget {
final String localGitRepoPath; final String localGitRepoPath;
final String remoteGitRepoPath; final String remoteGitRepoPath;
final String gitBaseDirectory; final String gitBaseDirectory;
final bool onBoardingCompleted;
StateContainer({ StateContainer({
@required this.localGitRepoConfigured, @required this.localGitRepoConfigured,
@ -26,6 +27,7 @@ class StateContainer extends StatefulWidget {
@required this.localGitRepoPath, @required this.localGitRepoPath,
@required this.remoteGitRepoPath, @required this.remoteGitRepoPath,
@required this.gitBaseDirectory, @required this.gitBaseDirectory,
@required this.onBoardingCompleted,
@required this.child, @required this.child,
}); });
@ -43,6 +45,7 @@ class StateContainer extends StatefulWidget {
st.appState.localGitRepoPath = localGitRepoPath; st.appState.localGitRepoPath = localGitRepoPath;
st.appState.remoteGitRepoPath = remoteGitRepoPath; st.appState.remoteGitRepoPath = remoteGitRepoPath;
st.appState.gitBaseDirectory = gitBaseDirectory; st.appState.gitBaseDirectory = gitBaseDirectory;
st.appState.onBoardingCompleted = onBoardingCompleted;
return st; return st;
} }
@ -207,11 +210,19 @@ class StateContainerState extends State<StateContainer> {
}); });
} }
void completeOnBoarding() {
setState(() {
this.appState.onBoardingCompleted = true;
_persistConfig();
});
}
Future _persistConfig() async { Future _persistConfig() async {
var pref = await SharedPreferences.getInstance(); var pref = await SharedPreferences.getInstance();
await pref.setBool( await pref.setBool(
"remoteGitRepoConfigured", appState.remoteGitRepoConfigured); "remoteGitRepoConfigured", appState.remoteGitRepoConfigured);
await pref.setString("remoteGitRepoPath", appState.remoteGitRepoPath); await pref.setString("remoteGitRepoPath", appState.remoteGitRepoPath);
await pref.setBool("onBoardingCompleted", appState.onBoardingCompleted);
} }
@override @override