How to change navigation animation using Flutter

前端 未结 5 1508
南笙
南笙 2020-12-12 16:30

Is there any way to change the default animation when navigating to/from a page in Flutter?

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-12 17:05

    I have done this by providing my own builders with custom map in pageTransitionsTheme for the app level theme.

    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Startup Name Generator Tile',
          home: RandomWords(),
          theme: new ThemeData(
            primaryColor: Colors.white,
            // Add the line below to get horizontal sliding transitions for routes.
            pageTransitionsTheme: PageTransitionsTheme(builders: {TargetPlatform.android: CupertinoPageTransitionsBuilder(),}),
          ),
        );
      }
    }
    

    Of course, I didn't add a map entry for ios as I use only android for TargetPlatform.

提交回复
热议问题