mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 03:19:11 +08:00
Add a very basic onBoardingScreen
This commit is contained in:
16
lib/app.dart
16
lib/app.dart
@ -7,6 +7,7 @@ import 'package:journal/state_container.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'screens/githostsetup_screens.dart';
|
||||
import 'screens/onboarding_screens.dart';
|
||||
|
||||
class JournalApp extends StatelessWidget {
|
||||
static FirebaseAnalytics analytics = FirebaseAnalytics();
|
||||
@ -24,9 +25,11 @@ class JournalApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var stateContainer = StateContainer.of(context);
|
||||
var onCompleted = () {
|
||||
stateContainer.completeGitHostSetup();
|
||||
};
|
||||
|
||||
var initialRoute = '/';
|
||||
if (!stateContainer.appState.onBoardingCompleted) {
|
||||
initialRoute = '/onBoarding';
|
||||
}
|
||||
|
||||
return MaterialApp(
|
||||
title: 'GitJournal',
|
||||
@ -38,11 +41,14 @@ class JournalApp extends StatelessWidget {
|
||||
accentColor: Color(0xff6d4c41),
|
||||
),
|
||||
navigatorObservers: <NavigatorObserver>[JournalApp.observer],
|
||||
initialRoute: '/',
|
||||
initialRoute: initialRoute,
|
||||
routes: {
|
||||
'/': (context) => HomeScreen(),
|
||||
'/settings': (context) => SettingsScreen(),
|
||||
'/setupRemoteGit': (context) => GitHostSetupScreen(onCompleted),
|
||||
'/setupRemoteGit': (context) =>
|
||||
GitHostSetupScreen(stateContainer.completeGitHostSetup),
|
||||
'/onBoarding': (context) =>
|
||||
OnBoardingScreen(stateContainer.completeOnBoarding),
|
||||
},
|
||||
debugShowCheckedModeBanner: false,
|
||||
//debugShowMaterialGrid: true,
|
||||
|
@ -10,6 +10,7 @@ class AppState {
|
||||
bool remoteGitRepoConfigured = false;
|
||||
|
||||
bool hasJournalEntries = false;
|
||||
bool onBoardingCompleted = false;
|
||||
|
||||
// FIXME: Make final
|
||||
String gitBaseDirectory = "";
|
||||
|
@ -38,6 +38,7 @@ Future runJournalApp() async {
|
||||
pref.getBool("remoteGitRepoConfigured") ?? false;
|
||||
var localGitRepoPath = pref.getString("localGitRepoPath") ?? "";
|
||||
var remoteGitRepoPath = pref.getString("remoteGitRepoPath") ?? "";
|
||||
var onBoardingCompleted = pref.getBool("onBoardingCompleted") ?? false;
|
||||
|
||||
if (JournalApp.isInDebugMode) {
|
||||
if (JournalApp.analytics.android != null) {
|
||||
@ -66,6 +67,7 @@ Future runJournalApp() async {
|
||||
localGitRepoPath: localGitRepoPath,
|
||||
remoteGitRepoPath: remoteGitRepoPath,
|
||||
gitBaseDirectory: dir.path,
|
||||
onBoardingCompleted: onBoardingCompleted,
|
||||
child: JournalApp(),
|
||||
));
|
||||
}
|
||||
|
76
lib/screens/onboarding_screens.dart
Normal file
76
lib/screens/onboarding_screens.dart
Normal 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),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@ class StateContainer extends StatefulWidget {
|
||||
final String localGitRepoPath;
|
||||
final String remoteGitRepoPath;
|
||||
final String gitBaseDirectory;
|
||||
final bool onBoardingCompleted;
|
||||
|
||||
StateContainer({
|
||||
@required this.localGitRepoConfigured,
|
||||
@ -26,6 +27,7 @@ class StateContainer extends StatefulWidget {
|
||||
@required this.localGitRepoPath,
|
||||
@required this.remoteGitRepoPath,
|
||||
@required this.gitBaseDirectory,
|
||||
@required this.onBoardingCompleted,
|
||||
@required this.child,
|
||||
});
|
||||
|
||||
@ -43,6 +45,7 @@ class StateContainer extends StatefulWidget {
|
||||
st.appState.localGitRepoPath = localGitRepoPath;
|
||||
st.appState.remoteGitRepoPath = remoteGitRepoPath;
|
||||
st.appState.gitBaseDirectory = gitBaseDirectory;
|
||||
st.appState.onBoardingCompleted = onBoardingCompleted;
|
||||
|
||||
return st;
|
||||
}
|
||||
@ -207,11 +210,19 @@ class StateContainerState extends State<StateContainer> {
|
||||
});
|
||||
}
|
||||
|
||||
void completeOnBoarding() {
|
||||
setState(() {
|
||||
this.appState.onBoardingCompleted = true;
|
||||
_persistConfig();
|
||||
});
|
||||
}
|
||||
|
||||
Future _persistConfig() async {
|
||||
var pref = await SharedPreferences.getInstance();
|
||||
await pref.setBool(
|
||||
"remoteGitRepoConfigured", appState.remoteGitRepoConfigured);
|
||||
await pref.setString("remoteGitRepoPath", appState.remoteGitRepoPath);
|
||||
await pref.setBool("onBoardingCompleted", appState.onBoardingCompleted);
|
||||
}
|
||||
|
||||
@override
|
||||
|
Reference in New Issue
Block a user