Skip to content

Instantly share code, notes, and snippets.

@Cretezy
Created May 7, 2020 11:40
Show Gist options
  • Save Cretezy/7ee30650093faa49401c44d7aa0f281d to your computer and use it in GitHub Desktop.
Save Cretezy/7ee30650093faa49401c44d7aa0f281d to your computer and use it in GitHub Desktop.
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