
import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:netrain_flutter_app/jishuaishuai/MVVMDemo/ViewDemo.dart';
import 'package:netrain_flutter_app/jishuaishuai/MVVMDemo/ViewModelDemo.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 'package:provider/provider.dart';

import 'laishanqi/Stateful_page.dart';
import 'laishanqi/Stateless_page.dart';
import 'laishanqi/layout_page.dart';
import 'laishanqi/netrain/DoctorMain.dart';
import 'laishanqi/netrain/maintab/DoctorHomePage.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(
      MultiProvider(
        providers: [
          ChangeNotifierProvider(
            create: (context) => ViewModelGet(),
          )
        ],
        child: 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) {
    setDesignWHD(375, 812);
    // 设置状态栏为透明
    SystemUiOverlayStyle systemUiOverlayStyle =
    SystemUiOverlayStyle(statusBarColor: Colors.transparent);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);

    return WillPopScope(
        child: MaterialApp(
          title: 'Flutter Demo',
          initialRoute: "main",
          theme: ThemeData(
            primaryColor: AppColors.titleBackgroundColor,
            hintColor: AppColors.hintText,
            accentColor: AppColors.mainColor,
            dividerColor: AppColors.dividerColor,
            scaffoldBackgroundColor: AppColors.scaffoldBackgroundColor,
            visualDensity: VisualDensity.adaptivePlatformDensity,
          ),
          localizationsDelegates: [
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
          ],
          supportedLocales: [
            const Locale('zh', 'CN'),
            const Locale('en', 'US'),
          ],

          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(context),
            "firstVC": (context) => jssPageDemo(),
            "car_details": (context) => CarDetailsPage(),
            "student": (context) => jssPageDemo(),
            "grid_page": (context) => GridPage(),
            "doctorHome": (context) => DoctorHomePage(),
            "bottom_page": (context) => BottomNavPage(),
            "doctor_MainPage": (context) => doctorMainPage(),
          },
        ),
        onWillPop: () async {
          Fluttertoast.showToast(msg: "退出");
          return true;
        });
  }
}

Widget mainPage(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text("NetRain Flutter学习计划"),
    ),
    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: Container(
        margin: EdgeInsets.only(left: 10, right: 10),
        child: Wrap(
          spacing: 10,
          children: [
            SwitchListTile(
                title: Text('${byName ? '' : '不'}通过路由名跳转'),
                value: byName,
                onChanged: (value) {
                  setState(() {
                    byName = value;
                  });
                }),
            _item("登陆", LoginPage(), 'login',context),
            _item("首页", LessGroupPage(), 'doctor_MainPage',context),
            _item("less页面", LessGroupPage(), 'less',context),
            _item("ful页面", FulGroupPage(), 'ful',context),
            _item("layout页面", LayoutPage(), 'layout',context),
            _item("拍照页面", PhotoApp(), 'photo',context),
            _item("登录网络请求", LoginRequestPage(), 'LoginRequestPage',context),
            _item("CustomTabPage", TabBarPage(), 'CustomTabPage',context),
            _item("PageView", SampleAppPage(), 'PageView',context),
            _item("LayoutDemo", LayoutDemo(), 'LayoutDemo',context),
            _item("listview页面", List_Page(), 'listPage',context),
            _item("jssDemo", jssPageDemo(), 'firstVC',context),
            _item("jssDemo", jssPageDemo(), 'student',context),
            _item("gridView", GridPage(), 'grid_page',context),
            _item("BottomNav", BottomNavPage(), 'bottom_page',context),
          ],
        ),
      ),
    );
  }

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