import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:netrain_flutter_app/common/Images.dart';

import 'secondpage.dart';

void main() {
  runApp(MyApp());
  // runApp(Login());
  // runApp(TestPage());

  print("启动");
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return WillPopScope(
        child: MaterialApp(
          title: 'Flutter Demo',
          // initialRoute: "/",
          theme: ThemeData(
            primarySwatch: Colors.blue,
            visualDensity: VisualDensity.adaptivePlatformDensity,
          ),
          home: Scaffold(
            appBar: AppBar(
              title: Text("路由"),
            ),
            body: RouterNavigator(title: 'Flutter Demo Home Page'),
          ),
          routes: <String, WidgetBuilder>{
            "key1": (context) => MyApp(),
            "key2": (context) => Second()
          },
        ),
        onWillPop: () async {
          Fluttertoast.showToast(msg: "退出");
          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("跳转", () async {
            var result = await Navigator.pushNamed(context, "key2",
                arguments: "this is value");
            print("返回值：$result");
          }),
          Image.asset(Images.bg_my_01)
        ],
      ),
    );
  }

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