Last active
October 13, 2021 12:39
-
-
Save IsmailAlamKhan/fcc8ac089a9e0b766fd9dbec3022f612 to your computer and use it in GitHub Desktop.
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(const MyApp()); | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Material App', | |
theme: ThemeData( | |
pageTransitionsTheme: PageTransitionsTheme(builders: { | |
for (var item in TargetPlatform.values) item: _TransitionBuilder(), | |
}), | |
), | |
routes: { | |
for (var i = 0; i < 6; i++) | |
'/screen${i + 1}': (context) => Screen(currentScreen: i + 1), | |
}, | |
initialRoute: '/screen1', | |
); | |
} | |
} | |
class Screen extends StatelessWidget { | |
const Screen({ | |
Key? key, | |
required this.currentScreen, | |
}) : super(key: key); | |
final int currentScreen; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
leading: currentScreen == 1 | |
? null | |
: BackButton( | |
onPressed: () { | |
if (currentScreen == 6) { | |
Navigator.of(context) | |
.popUntil(ModalRoute.withName('/screen3')); | |
} else { | |
Navigator.of(context).pop(); | |
} | |
}, | |
), | |
title: Text('Screen $currentScreen'), | |
), | |
body: currentScreen == 6 | |
? null | |
: Center( | |
child: ElevatedButton( | |
onPressed: () { | |
Navigator.of(context) | |
.pushNamed('/screen${currentScreen + 1}'); | |
}, | |
child: const Text('Next'), | |
), | |
), | |
); | |
} | |
} | |
class _TransitionBuilder extends PageTransitionsBuilder { | |
@override | |
Widget buildTransitions<T>( | |
PageRoute<T> route, | |
BuildContext context, | |
Animation<double> animation, | |
Animation<double> secondaryAnimation, | |
Widget child, | |
) => | |
FadeTransition(opacity: animation, child: child); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment