import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:netrain_flutter_app/xuehao/BottomNavpage.dart';
import 'package:netrain_flutter_app/xuehao/car_details.dart';
import 'package:netrain_flutter_app/common/AppColors.dart';
import 'package:netrain_flutter_app/xuehao/grid_page.dart';
import 'package:netrain_flutter_app/xuehao/list_page.dart';

import 'laishanqi/Stateful_page.dart';
import 'laishanqi/Stateless_page.dart';
import 'laishanqi/layout_page.dart';
import 'laishanqi/netrain/user/loginPage.dart';
import 'laishanqi/netrain/user/RegisterPage.dart';
import 'laishanqi/photo.dart';
import 'zhangfeng/UserModel.dart';
import 'zhangfeng/LoginPage.dart';
import 'zhangfeng/CustomTabPage.dart';
import 'zhangfeng/TestPage.dart';
import 'zhangfeng/TabBarPage.dart';
import 'zhangfeng/LayoutDemo.dart';

import 'jishuaishuai/firstVC.dart';



void main() {
  runApp(MyApp());
  // runApp(Login());
  // runApp(TestPage());
  UserModel.getModel();

  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: "main",
          theme: ThemeData(
            primaryColor: Color(AppColors.titleBackgroundColor),
            hintColor: Color(AppColors.hintText),
            accentColor: Color(AppColors.mainColor),
            dividerColor: Color(AppColors.dividerColor),
            scaffoldBackgroundColor: Color(AppColors.scaffoldBackgroundColor),
            visualDensity: VisualDensity.adaptivePlatformDensity,
          ),
          routes: <String, WidgetBuilder>{
            "less": (context) => LessGroupPage(),
            "ful": (context) => FulGroupPage(),
            "layout": (context) => LayoutPage(),
            "photo": (context) => PhotoApp(),
            "register": (context) => RegisterPage(),
            "login": (context) => LoginPage(),
            "listPage":(context) => List_Page(),
            "CustomTabPage":(context) => TabBarPage(),
            "LoginRequestPage":(context) => LoginRequestPage(),
            "PageView":(context) => SampleAppPage(),
            "LayoutDemo":(context) => LayoutDemo(),
            "main": (context) => mainPage(),
            "firstVC":(context) => jssPageDemo(),
            "car_details":(context) =>CarDetailsPage(),
            "student":(context) => jssPageDemo(),
            "car_details":(context) =>CarDetailsPage(),
            "grid_page":(context) =>GridPage(),
            "bottom_page":(context) =>BottomNavPage(),
          },
        ),
        onWillPop: () async {
          Fluttertoast.showToast(msg: "退出");
          return true;
        });

  }

}
Widget mainPage(){
  return Scaffold(
    appBar: AppBar(
      title: Text("路由"),
    ),
    body: RouterNavigator(title: 'Flutter Demo Home Page'),
  );
}

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 = true;

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: [
          SwitchListTile(
              title: Text('${byName ? '' : '不'}通过路由名跳转'),
              value: byName,
              onChanged: (value) {
                setState(() {
                  byName = value;
                });
              }),
          _item("less页面", LessGroupPage(), 'less'),
          _item("ful页面", FulGroupPage(), 'ful'),
          _item("layout页面", LayoutPage(), 'layout'),
          _item("拍照页面", PhotoApp(), 'photo'),
          _item("登陆", LoginPage(), 'login'),
          _item("登录网络请求", LoginRequestPage(), 'LoginRequestPage'),
          _item("CustomTabPage",TabBarPage(),'CustomTabPage'),
          _item("PageView",SampleAppPage(),'PageView'),
          _item("LayoutDemo", LayoutDemo(), 'LayoutDemo'),
          _item("listview页面",List_Page(),'listPage'),
          _item("jssDemo", jssPageDemo(), 'firstVC'),
          _item("jssDemo", jssPageDemo(), 'student'),
          _item("gridView",GridPage(),'grid_page'),
          _item("BottomNav",BottomNavPage(),'bottom_page'),
        ],
      ),
    );
  }

  _item(String title, page, String routeName) {
    return Container(
      child: ElevatedButton(
        onPressed: () {
          if (byName) {
            Navigator.pushNamed(context, routeName);
          } else {
            Navigator.push(context,MaterialPageRoute(builder: (context) => page,));
          }
        },
        child: Text(title),
      ),
    );
  }
}

