2

在我的颤振应用程序中,我想在路线之间删除,所以当用户按下它时,它将转到上一个屏幕。以下是我的屏幕流程。

  1. 仪表板登陆屏幕。
  2. 用户单击“主题列表”按钮并进入“主题列表”页面。
  3. 用户单击“创建新主题”并进入带有表单的新页面以填写该主题的基本信息。
  4. 填写表单后,用户单击保存按钮并使用他刚刚创建的主题详细信息登陆新页面。
  5. 现在如果用户点击返回,他/她应该登陆主题列表页面而不是创建新主题页面。
  6. 此外,如果他从“主题列表”页面再次按回,他应该会看到仪表板,而不是退出应用程序。

提前谢谢你。

4

1 回答 1

3

当你想跳过页面时,只需使用pushReplacement而不是。pushback

在此处输入图像描述

import 'dart:math';

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter naviagtion',
      theme: ThemeData(
        backgroundColor: Colors.white,
        primarySwatch: Colors.green,
      ),
      home: DashboardLandingScreen(),
    );
  }
}

class DashboardLandingScreen extends StatelessWidget {
  static Route route() => MaterialPageRoute(
        builder: (context) => DashboardLandingScreen(),
      );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        alignment: Alignment.center,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text('Dashboard landing screen.'),
            RaisedButton(
              child: Text('List of Topics'),
              onPressed: () => Navigator.of(context).push(
                TopicsListScreen.route(),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class TopicsListScreen extends StatelessWidget {
  static Route route() => MaterialPageRoute(
        builder: (context) => TopicsListScreen(),
      );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        alignment: Alignment.center,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text('List of Topics'),
            RaisedButton(
              child: Text('Create New Topic'),
              onPressed: () => Navigator.of(context).push(
                NewTopic.route(),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class NewTopic extends StatelessWidget {
  static Route route() => MaterialPageRoute(
        builder: (context) => NewTopic(),
      );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        alignment: Alignment.center,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text('page: new topic'),
            RaisedButton(
              child: Text('Save'),
              onPressed: () => Navigator.of(context).pushReplacement(
                CreatedTopicDetails.route(),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class CreatedTopicDetails extends StatelessWidget {
  static Route route() => MaterialPageRoute(
        builder: (context) => CreatedTopicDetails(),
      );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        alignment: Alignment.center,
        child: Text('page: created topic details'),
      ),
    );
  }
}
于 2020-01-08T17:24:41.143 回答