FLUTTER WEEK 5
FLUTTER WEEK 5
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
OUTPUT:
4 b. Implement navigation with named routes.
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
title: 'Named Routes Demo',
// Start the app with the "/" named route. In
this case, the app starts
// on the FirstScreen widget.
initialRoute: '/',
routes: {
// When navigating to the "/" route, build
the FirstScreen widget.
'/': (context) => const FirstScreen(),
// When navigating to the "/second" route,
build the SecondScreen widget.
'/second': (context) => const
SecondScreen(),
},
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('First Screen'),
),
body: Center(
child: ElevatedButton(
// Within the `FirstScreen` widget
onPressed: () {
// Navigate to the second screen using
a named route.
Navigator.pushNamed(context,
'/second');
},
child: const Text('Launch screen'),
),
),
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Second Screen'),
),
body: Center(
child: ElevatedButton(
// Within the SecondScreen widget
onPressed: () {
// Navigate back to the first screen by
popping the current route
// off the stack.
Navigator.pop(context);
},
child: const Text('Go back!'),
),
),
);
}
}
OUTPUT: