Skip to content

Instantly share code, notes, and snippets.

@mrcndn
Created August 5, 2023 21:24
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 mrcndn/63605a22db2bd742d3f4eb6169fc1c88 to your computer and use it in GitHub Desktop.
Save mrcndn/63605a22db2bd742d3f4eb6169fc1c88 to your computer and use it in GitHub Desktop.
go_router test
import 'package:animations/animations.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
void main() {
runApp(const MyApp());
}
final router = GoRouter(
initialLocation: '/',
routes: [
ShellRoute(
builder: (BuildContext context, GoRouterState state, Widget child) {
return Scaffold(
backgroundColor: Colors.lightGreen,
body: child,
bottomNavigationBar: BottomNavigationBar(
showSelectedLabels: false,
showUnselectedLabels: false,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home_outlined),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.person_outline),
label: 'Camera',
),
],
onTap: (int index) {
if (index == 0) {
context.go('/');
} else if (index == 1) {
context.go('/anim');
} else if (index == 2) {}
},
),
);
},
routes: [
GoRoute(
path: '/anim',
pageBuilder: (context, state) => CustomTransitionPage(
key: state.pageKey,
child: const Center(
child: Text('With transition'),
),
transitionsBuilder:
(context, animation, secondaryAnimation, child) =>
SharedAxisTransition(
animation: animation,
secondaryAnimation: secondaryAnimation,
transitionType: SharedAxisTransitionType.scaled,
child: child,
),
),
),
GoRoute(
path: '/',
builder: (context, state) => const Center(
child: Text('home'),
),
),
],
),
],
);
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routerConfig: router,
title: 'Flutter Test',
debugShowCheckedModeBanner: false,
theme: ThemeData(
scaffoldBackgroundColor: Colors.cyan,
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.red,
brightness: Brightness.dark,
).copyWith(background: Colors.blue),
useMaterial3: true,
brightness: Brightness.dark,
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment