FondleTalk/lib/main.dart
2025-01-11 17:50:58 +08:00

115 lines
4.3 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:talk/tools/creat/create_page.dart';
import 'package:talk/tools/home_page.dart';
import 'package:talk/tools/login/login_page.dart';
import 'package:talk/tools/me/about_page.dart';
import 'package:talk/tools/me/algorithm_filing_page.dart';
import 'package:talk/tools/me/close_teenage_mode_page.dart';
import 'package:talk/tools/me/report_page.dart';
import 'package:talk/tools/me/setting_page.dart';
import 'package:talk/tools/me/teenage_mode_page.dart';
import 'package:talk/tools/me/teenage_password_page.dart';
import 'package:talk/tools/me/teenage_retrieve_password_page.dart';
import 'package:talk/tools/search/search_page.dart';
import 'package:talk/tools/shop/account_page.dart';
import 'package:talk/tools/shop/problem_page.dart';
import 'package:talk/tools/shop/shop_page.dart';
import 'package:talk/tools/start_page.dart';
import 'common/EventBusUtil.dart';
import 'common/Global.dart';
Future<void> main() async {
await runZonedGuarded(() async {
WidgetsFlutterBinding.ensureInitialized();
Global.initialize().then((e) {
Global();
runApp(const ChatApp());
if (Platform.isAndroid) {
// 以下两行 设置android状态栏为透明的沉浸。写在组件渲染之后是为了在渲染后进行set赋值覆盖状态栏写在渲染之前MaterialApp组件会覆盖掉这个值。
SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(statusBarColor: Colors.transparent);
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
}
});
}, (error, stackTrace) {
print("error==$error");
});
}
class ChatApp extends StatefulWidget {
const ChatApp({super.key});
@override
State<ChatApp> createState() => _ChatAppState();
}
class _ChatAppState extends State<ChatApp> {
// 注册方法等待被原生通过invokeMethod唤起
Future<dynamic> nativeCallHandler(MethodCall methodCall) async {
switch (methodCall.method) {
case "AlipaySuccess": //支付宝支付完成
// EasyLoading.showToast("支付成功");
EventBusUtil.fire(PaySuccess());
break;
case "wxPaySuccess": //微信支付完成
// EasyLoading.showToast("微信支付成功");
EventBusUtil.fire(PaySuccess());
break;
case "payError": //支付失败
EasyLoading.showToast("支付失败");
break;
case "AdSuccess": //广告播放完成
EventBusUtil.fire(AdSuccess());
break;
}
}
@override
void initState() {
// TODO: implement initState
Global.method.setMethodCallHandler(nativeCallHandler);
super.initState();
//白色
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: '妙语星河',
home: const StartPage(),
//注册路由
routes: <String, WidgetBuilder>{
'/HomePage': (BuildContext context) => const HomePage(),
'/SearchPage': (BuildContext context) => const SearchPage(),
'/LoginPage': (BuildContext context) => const LoginPage(),
'/AccountPage': (BuildContext context) => const AccountPage(),
'/ProblemPage': (BuildContext context) => const ProblemPage(),
'/ShopPage': (BuildContext context) => const ShopPage(),
'/SettingPage': (BuildContext context) => const SettingPage(),
'/AboutPage': (BuildContext context) => const AboutPage(),
'/ReportPage': (BuildContext context) => const ReportPage(),
'/TeenageModePage': (BuildContext context) => const TeenageModePage(),
'/TeenagePasswordPage': (BuildContext context) => const TeenagePasswordPage(),
'/CloseTeenageModePage': (BuildContext context) => const CloseTeenageModePage(),
'/TeenageRetrievePasswordPage': (BuildContext context) => const TeenageRetrievePasswordPage(),
'/AlgorithmFilingPage': (BuildContext context) => const AlgorithmFilingPage(),
'/CreatePage': (BuildContext context) => const CreatePage(),
},
debugShowMaterialGrid: false,
//显示网格
debugShowCheckedModeBanner: false,
//去掉右上角的debug
builder: EasyLoading.init(),
);
}
}