Skip to content

Instantly share code, notes, and snippets.

@ybakos
Last active February 14, 2020 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ybakos/9ea510f0c928267ccdecee84bc2a2b66 to your computer and use it in GitHub Desktop.
Save ybakos/9ea510f0c928267ccdecee84bc2a2b66 to your computer and use it in GitHub Desktop.
CS 492 Week 7 Exploration 2 Exercise Navigation
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)
)
);
}
}
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