Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:routemaster/routemaster.dart';
- class App extends StatelessWidget {
- const App({super.key});
- @override
- Widget build(BuildContext context) {
- return MaterialApp.router(
- routerDelegate: RoutemasterDelegate(routesBuilder: (context) => routes),
- routeInformationParser: const RoutemasterParser(),
- );
- }
- }
- final routes = RouteMap(
- routes: {
- '/':(route) => const MaterialPage(
- key: ValueKey('first'),
- child: firstPage,
- ),
- '/second':(route) => const MaterialPage(
- key: ValueKey('second'),
- child: secondPage,
- ),
- },
- );
- const firstPage = AppPage(
- title: Text('First'),
- body: Text('First'),
- color: Colors.purple
- );
- const secondPage = AppPage(
- title: Text('Second'),
- body: Text('Second'),
- color: Colors.green
- );
- class AppPage extends StatelessWidget {
- final Text title;
- final Text body;
- final Color color;
- const AppPage({
- super.key,
- required this.title,
- required this.body,
- required this.color
- });
- @override
- Widget build (BuildContext context) {
- return Scaffold(
- drawer: Drawer(
- child: ListView(
- children: [
- ListTile(
- title: const Text('First'),
- onTap: () => Routemaster.of(context).push('/'),
- ),
- ListTile(
- title: const Text('Second'),
- onTap: () => Routemaster.of(context).push('/second'),
- ),
- ],
- ),
- ),
- appBar: AppBar(
- title: title,
- ),
- body: Container(
- decoration: BoxDecoration(color: color),
- child: Center(child: body),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement