Last active
February 14, 2020 19:23
-
-
Save ybakos/9ea510f0c928267ccdecee84bc2a2b66 to your computer and use it in GitHub Desktop.
CS 492 Week 7 Exploration 2 Exercise Navigation
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
import 'package:flutter/material.dart'; | |
void main() => runApp(App()); | |
class App extends StatelessWidget { | |
// TODO: Declare a Map containing two routes, | |
// one for Exercise and one for Alpha. | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Exercise() // TODO: remove the home parameter | |
// TODO: Supply the routes to MaterialApp | |
); | |
} | |
} | |
class Exercise extends StatelessWidget { | |
// TODO: Define a static string for routeName | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [label(context), button(context)] | |
) | |
) | |
); | |
} | |
Widget label(BuildContext context) { | |
return Text('Navigation Exercise', | |
style: Theme.of(context).textTheme.headline4); | |
} | |
Widget button(BuildContext context) { | |
return RaisedButton( | |
child: Text('Click Me!'), | |
onPressed: () { displayAlpha(context); } | |
); | |
} | |
void displayAlpha(BuildContext context) { | |
// TODO: Use Navigator.pushNamed. | |
Navigator.push( | |
context, MaterialPageRoute( | |
builder: (context) => Alpha()) | |
); | |
} | |
} | |
class Alpha extends StatelessWidget { | |
// TODO: Define a static string for routeName | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(), | |
body: Center( | |
child: Text('Notice the Back Button in the App Bar\n' | |
'We get this for free!\n' | |
'Managed by the Navigator.\n', | |
style: Theme.of(context).textTheme.headline4) | |
) | |
); | |
} | |
} | |
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
import 'package:flutter/material.dart'; | |
void main() => runApp(App()); | |
class App extends StatelessWidget { | |
// DONE | |
static final routes = { | |
Exercise.routeName: (context) => Exercise(), | |
Alpha.routeName: (context) => Alpha() | |
}; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
routes: routes, // DONE | |
); | |
} | |
} | |
class Exercise extends StatelessWidget { | |
// DONE | |
static final routeName = '/'; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [label(context), button(context)] | |
) | |
) | |
); | |
} | |
Widget label(BuildContext context) { | |
return Text('Navigation Exercise', | |
style: Theme.of(context).textTheme.headline4); | |
} | |
Widget button(BuildContext context) { | |
return RaisedButton( | |
child: Text('Click Me!'), | |
onPressed: () { displayAlpha(context); } | |
); | |
} | |
void displayAlpha(BuildContext context) { | |
// DONE | |
Navigator.pushNamed(context, Alpha.routeName); | |
} | |
} | |
class Alpha extends StatelessWidget { | |
// DONE | |
static final routeName = 'alpha'; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(), | |
body: Center( | |
child: Text('Notice the Back Button in the App Bar\n' | |
'We get this for free!\n' | |
'Managed by the Navigator.\n', | |
style: Theme.of(context).textTheme.headline4) | |
) | |
); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment