-
-
Save jimmyff/eb68aeb0406c40ff3ecf0742f24e15fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<void> main() async { | |
await WidgetsFlutterBinding.ensureInitialized(); | |
final prefs = await SharedPreferences.getInstance(); | |
final keyValueStore = FlutterKeyValueStore(prefs); | |
final store = createStore(Client(), keyValueStore); | |
runApp(SocialClientApp(store)); | |
} | |
class SocialClientApp extends StatefulWidget { | |
SocialClientApp(this.store); | |
final Store<AppState> store; | |
@override | |
_SocialClientAppState createState() => _SocialClientAppState(); | |
} | |
class _SocialClientAppState extends State<SocialClientApp> { | |
@override | |
void initState() { | |
super.initState(); | |
widget.store.dispatch(InitAction()); | |
} | |
final themeData = ThemeData( | |
primaryColor: Colors.deepPurple, | |
primaryColorBrightness: Brightness.dark, | |
accentColor: Colors.amber[800], | |
accentColorBrightness: Brightness.dark, | |
scaffoldBackgroundColor: Colors.white, | |
buttonTheme: ButtonThemeData( | |
buttonColor: Colors.deepPurple, | |
textTheme: ButtonTextTheme.primary, | |
), | |
); | |
final localisationDelegates = <LocalizationsDelegate>[ | |
const MobileLocalizationsDelegate(), | |
GlobalMaterialLocalizations.delegate, | |
GlobalWidgetsLocalizations.delegate, | |
]; | |
@override | |
Widget build(BuildContext context) { | |
return StoreProvider<AppState>( | |
store: widget.store, | |
child: MaterialApp( | |
title: 'App name', | |
localizationsDelegates: localisationDelegates, | |
theme: themeData, | |
// onGenerateRoute: _getRoute, | |
home: Scaffold( | |
body: MaterialApp( | |
localizationsDelegates: localisationDelegates, | |
theme: themeData, | |
supportedLocales: MobileLocalizationsDelegate.supportedLocales(), | |
navigatorKey: NavigatorHolder.navigatorKey, | |
initialRoute: '/', | |
onGenerateRoute: _getRoute, | |
home: SnackBarReceiver( | |
widget.store.state.authStoreState.isAuthenticated() | |
? widget.store.state.authStoreState.status.authState == | |
AuthState.authenticated | |
? MatchQueueScreen() | |
: NewAccountScreen() | |
: LoadingScreen(), | |
), | |
), | |
bottomNavigationBar: | |
widget.store.state.authStoreState.status?.authState != | |
AuthState.authenticated | |
? null | |
: BottomNavigationBar( | |
items: const <BottomNavigationBarItem>[ | |
BottomNavigationBarItem( | |
icon: Icon(Icons.search), | |
title: Text('People'), | |
), | |
BottomNavigationBarItem( | |
icon: Icon(Icons.person_outline), | |
title: Text('You'), | |
), | |
BottomNavigationBarItem( | |
icon: Icon(Icons.chat_bubble_outline), | |
title: Text('Chat'), | |
), | |
], | |
currentIndex: 0, | |
), | |
)), | |
); | |
} | |
Route _getRoute(RouteSettings settings) { | |
switch (settings.name) { | |
case '/discover': | |
return _buildRoute(settings, MatchQueueScreen()); | |
case '/new_account': | |
return _buildRoute(settings, NewAccountScreen()); | |
case '/auth': | |
return _buildRoute(settings, AuthScreen()); | |
case '/add_photo': | |
return _buildRoute(settings, AddPhotoScreen()); | |
default: | |
return _buildRoute(settings, LoadingScreen()); | |
} | |
} | |
MaterialPageRoute _buildRoute(RouteSettings settings, Widget builder) { | |
return MaterialPageRoute( | |
settings: settings, | |
builder: (BuildContext context) => builder, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment