如何在TargetPlatform.android上实现侧滑关闭页面?

时间:2018-09-08 02:31:53

标签: flutter flutter-animation

Flutter设置TargetPlatform.iOS

new MaterialApp(
  title: 'Mian',
  theme: new ThemeData(
    primarySwatch: Colors.orange,
    platform: TargetPlatform.iOS,
  )
)

可以跳过关闭页面。

Flutter设置TargetPlatform.android

new MaterialApp(
  title: 'Mian',
  theme: new ThemeData(
    primarySwatch: Colors.orange,
    platform: TargetPlatform.android,
  )
)

无法跳过关闭页面。

2 个答案:

答案 0 :(得分:2)

您可以在按下CupertinoPageRoute时使用Widget进行操作。

首先,您必须导入cupertino:

import 'package:flutter/cupertino.dart';

然后使用Navigator

Navigator.of(context)
            .push(CupertinoPageRoute(builder: (context) => YourNewWidgetPage()));

答案 1 :(得分:0)

通过阅读文章,我有新的答案要更新,这种方式更加友好。

enter code class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
  title: 'Flutter Demo',
  theme: ThemeData(
      primarySwatch: Colors.blue,
      pageTransitionsTheme: PageTransitionsTheme(builders: {
        TargetPlatform.android: CupertinoPageTransitionsBuilder(),
        TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
      })),
  routes: {
    "/": (BuildContext context) =>
        MyHomePage(title: 'Flutter Demo Home Page'),
    "/two": (BuildContext context) => TwoPage(),
  },
);
}
}

Demo Gif

感谢Arvinth的文章:https://medium.com/flutter-community/page-transitions-using-themedata-in-flutter-c24afadb0b5d