import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:http/http.dart';
import 'package:netrain_flutter_app/douwen/dwMain.dart';

class Second extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
        child: Scaffold(
          appBar: AppBar(
            title: Text("哦吼2"),
          ),
          body: RouterNavigator(title: 'Flutter Demo Home Page'),
        ),
        onWillPop: () async {
          Fluttertoast.showToast(msg: "哦吼2");
          var args = ModalRoute.of(context).settings.arguments;
          return true;
        });
  }
}

class RouterNavigator extends StatefulWidget {
  RouterNavigator({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _RouterNavigatorState createState() => _RouterNavigatorState();
}

class _RouterNavigatorState extends State<RouterNavigator> {
  bool byName = false;

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: [
          _item("跳转", () {
            Navigator.of(context).popUntil(ModalRoute.withName("key1"));
          }),
          _item("跳转", () {
            Navigator.pushNamed(context,"key2");
          })
        ],
      ),
    );
  }

  _item(String title, VoidCallback onPressed) {
    return Container(
      child: RaisedButton(
        onPressed: onPressed,
        child: Text(title),
      ),
    );
  }
}
