import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart';
import 'package:gmalpha_flutter/Annotations/RouterCenterRestore.mark.dart';
import 'package:gmalpha_flutter/Error_Page.dart';
import 'package:gmalpha_flutter/commonModel/net/Api.dart';
import 'package:gmalpha_flutter/messageModel/home/message_home.dart';

import 'comment_suggest.dart';

void main() async {
//  await applicationInit();
  print("RESIGN!!!");
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    FlutterBoost.singleton.registerPageBuilders({
      'comment_suggest': (pageName, params, _) => CommentSuggest(params),
      'message_home': (pageName, params, _) => MessageHomePage(params),
      'album': (pageName, params, _) {
        var param = params["needCamera"] as bool;
        var param1 = params["maxCount"] as int;
        var param2 = params["selectedPath"] as List<String>;
        return RouterCenterImpl()
            .findAlbumRouter()
            .getAlbumPage(param, param1, param2);
      },
      "prestige": (pageName, params, _) {
        String fromPage = params["fromPage"];
        if (params == null ||
            fromPage == null ||
            Api.getInstance().initBuildConfig(params) == null) {
          return ErrorPage("出错：需要传递的参数为空");
        }
        int userId = int.parse(params["userId"]);
        return RouterCenterImpl()
            .findPrestigeRouter()
            ?.getReputationsPage(userId, params["userName"], fromPage);
      },
      "activity_report": (pageName, params, _) {
        String fromPage = params["fromPage"];
        if (params == null ||
            fromPage == null ||
            Api.getInstance().initBuildConfig(params) == null) {
          return ErrorPage("出错：需要传递的参数为空");
        }
        return RouterCenterImpl()
            .findActivityReportRouter()
            ?.getActivityReportPage(
                params["survey_record_id"] == null
                    ? null
                    : int.parse(params["survey_record_id"]),
                params["template_id"] == null
                    ? null
                    : int.parse(params["template_id"]),
                fromPage);
      }
    });
    FlutterBoost.handleOnStartPage();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Boost example',
      debugShowCheckedModeBanner: false,
      //  initialRoute: '/test',
////      调试的时候可以打开

    //  routes: {
    //    // '/': (context) => CommentSuggest({"Cookie":" _gm_token=7e48641558699683; sessionid=nb3ze4ur7ucosln8sd8pzwojddenv9ym; _gtid=a1bc0a387e1911e996b9525400fa516d4094"}),
    //     '/': (context) {
    //       Api.getInstance().initBuildConfig({'Cookie':'_gm_token=72ee1c1569466411; _gtid=58d3cc14df8711e99736525400e82fab81; sessionid=vhksn66854pejzjwi8ljhrmcew3domh2'
    //       ,"buildConfig":"debug"});
    //       return RouterCenterImpl().findActivityReportRouter()?.getActivityReportPage(169, 1, '');
    //     },
    //  },


      //调试的时候可以打开
      builder: FlutterBoost.init(postPush: _onRoutePushed),
      theme: new ThemeData(
        primaryColor: Colors.white,
        backgroundColor: Color(0xFFEFEFEF),
        accentColor: Color(0xFF888888),
        textTheme: TextTheme(
          //设置Material的默认字体样式
          body1: TextStyle(color: Color(0xFF888888), fontSize: 16.0),
        ),
        iconTheme: IconThemeData(
          color: Color(0xFFEFEFEF),
          size: 35.0,
        ),
      ),
    );
  }

  void _onRoutePushed(
      String pageName, String uniqueId, Map params, Route route, Future _) {
    print("PUSHED $pageName");
  }
}
