Created
May 7, 2020 11:40
-
-
Save Cretezy/7ee30650093faa49401c44d7aa0f281d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class LoginScreen extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("Login"), | |
), | |
body: Center( | |
// Login button | |
child: ModuleBuilder<AuthModule>( | |
builder: (context, authModule) { | |
return RaisedButton( | |
child: Text("Login"), | |
onPressed: () async { | |
// Call action | |
await authModule.login(); | |
Navigator.pushReplacement( | |
context, | |
MaterialPageRoute(builder: (context) => CounterScreen()), | |
); | |
}, | |
); | |
}, | |
), | |
), | |
); | |
} | |
} | |
class CounterScreen extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("Counter"), | |
), | |
body: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
// Our counter module | |
ModuleBuilder<CounterModule>( | |
builder: (context, counterModule) { | |
return Row( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
RaisedButton( | |
child: Text("Increment"), | |
onPressed: () => counterModule.increment(), | |
), | |
Padding( | |
padding: const EdgeInsets.symmetric(horizontal: 16), | |
child: Text(counterModule.counter.toString()), | |
), | |
RaisedButton( | |
child: Text("Decrement"), | |
onPressed: () => counterModule.decrement(), | |
), | |
], | |
); | |
}, | |
), | |
// Logout button | |
ModuleBuilder<AuthModule>( | |
builder: (context, authModule) { | |
return RaisedButton( | |
child: Text("Logout"), | |
onPressed: () async { | |
await authModule.logout(); | |
Navigator.pushReplacement( | |
context, | |
MaterialPageRoute(builder: (context) => LoginScreen()), | |
); | |
}, | |
); | |
}, | |
), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment