【问题标题】:Change route with Swipe使用滑动更改路线
【发布时间】:2018-08-08 21:16:35
【问题描述】:

我想通过简单的向左滑动来改变一个窗口,我需要 2 个窗口,当用户向右滑动时,我想改变我的路线。

我正在使用命名路由。

void main() => runApp(new HeatMapApp());

class HeatMapApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
        title: 'HeatMap',
        initialRoute: '/',
        routes: {
          '/': (context) => new Main(),
          '/home': (context) => new Home()
        },
        theme: new ThemeData(
            primaryColor: Colors.black
        )
    );
  }
}

这是我在我的应用程序中的代码,主文件现在没有太多数据,我想知道滑动事件重定向到'home'路径。

Main.dart

class Main extends StatelessWidget {
  final bool _isLoggedIn = true;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: _isLoggedIn ? AppBar (
            title: Text('Logged In')
        ) : null,
        body: Center(
          child: Text('Hello World!')
        )
    );
  }

}

【问题讨论】:

    标签: dart flutter


    【解决方案1】:

    我认为Dismissible Widget 非常适合您的要求

      class Main extends StatelessWidget {
        final bool _isLoggedIn = true;
    
        _nextPage(BuildContext context) async {
          Navigator.of(context).pushReplacementNamed("/home");
        }
    
        @override
        Widget build(BuildContext context) {
          return Dismissible(
              key: new ValueKey("dismiss_key"),
              direction: DismissDirection.endToStart,
              child: Scaffold(
                  appBar: _isLoggedIn ? AppBar(title: Text('Logged In')) : null,
                  body: Center(child: Text('Hello World!'))),
              onDismissed: (direction) {
                if (direction == DismissDirection.endToStart) {
                  _nextPage(context);
                }
              });
        }
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-20
      • 1970-01-01
      • 1970-01-01
      • 2022-01-11
      • 2017-05-26
      • 1970-01-01
      • 2014-07-08
      • 2013-09-04
      相关资源
      最近更新 更多