You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

283 lines
12 KiB

import 'dart:io';
import 'dart:ui';
import 'package:event_bus/event_bus.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bmflocation/bdmap_location_flutter_plugin.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:huixiang/address/address_map_page.dart';
import 'package:huixiang/address/edit_address_page.dart';
import 'package:huixiang/article/hot_article_details_page.dart';
import 'package:huixiang/article/hot_article_item.dart';
import 'package:huixiang/article/video_playback_page.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/home/founder_story_page.dart';
import 'package:huixiang/integral/integral_detailed_page.dart';
import 'package:huixiang/integral/integral_page.dart';
import 'package:huixiang/integral_store/integral_store_details_page.dart';
import 'package:huixiang/login/login_page.dart';
import 'package:huixiang/message/main_message_page.dart';
import 'package:huixiang/message/system_message.dart';
import 'package:huixiang/mine/coupons_page.dart';
import 'package:huixiang/mine/edit_name.dart';
import 'package:huixiang/mine/mine_card_invalid_page.dart';
import 'package:huixiang/mine/mine_card_page.dart';
import 'package:huixiang/mine/mine_vip_level_page.dart';
import 'package:huixiang/mine/mine_wallet_page.dart';
import 'package:huixiang/mine/recharge_page.dart';
import 'package:huixiang/mine/user_info_page.dart';
import 'package:huixiang/mine/vip_balance_page.dart';
import 'package:huixiang/mine/vip_card_page.dart';
import 'package:huixiang/mine/vip_detail_page.dart';
import 'package:huixiang/order/edit_remarks_page.dart';
import 'package:huixiang/order/exchange_history_page.dart';
import 'package:huixiang/order/exchange_order_page.dart';
import 'package:huixiang/order/exchange_order_success_page.dart';
import 'package:huixiang/order/exchange_order_detail_page.dart';
import 'package:huixiang/order/logistics_information_page.dart';
import 'package:huixiang/order/order_detail_page.dart';
import 'package:huixiang/order/order_history_page.dart';
import 'package:huixiang/order/store_selector_page.dart';
import 'package:huixiang/order/write_off_page.dart';
import 'package:huixiang/order/write_off_success_page.dart';
import 'package:huixiang/setting/about_page.dart';
import 'package:huixiang/setting/help_feedback_page.dart';
import 'package:huixiang/setting/permission_setting_page.dart';
import 'package:huixiang/setting/setting_page.dart';
import 'package:huixiang/setting/treaty_page.dart';
import 'package:huixiang/union/location_map_page.dart';
import 'package:huixiang/union/store_details_page.dart';
import 'package:huixiang/union/union_details_page.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/utils/flutter_utils.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:sharesdk_plugin/sharesdk_interface.dart';
import 'package:sharesdk_plugin/sharesdk_register.dart';
import 'package:tpns_flutter_plugin/android/xg_android_api.dart';
import 'package:tpns_flutter_plugin/tpns_flutter_plugin.dart';
import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart';
import 'home/guide_page.dart';
import 'main_page.dart';
import 'mine/manage_address_page.dart';
import 'mine/roll_center_page.dart';
void main() async {
if (Platform.isAndroid) {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(statusBarColor: Colors.transparent));
}
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
Locale locale;
if (sharedPreferences.containsKey("language") &&
sharedPreferences.getString("language") == "zh") {
locale = Locale.fromSubtags(languageCode: 'zh', countryCode: 'CN');
} else {
locale = Locale.fromSubtags(languageCode: 'zh', countryCode: 'TW');
}
initSdk();
bool? isFirst = sharedPreferences.getBool("isFirst");
print("isFirst:$isFirst");
runApp(MyApp(locale, isFirst));
}
XgFlutterPlugin xgFlutterPlugin = XgFlutterPlugin();
initSdk() async {
///ios 调用startXg前需要调用此方法
xgFlutterPlugin.configureClusterDomainName("tpns.sh.tencent.com");
xgFlutterPlugin.setEnableDebug(true);
///此处配置为iOS的appID信息,Android信息在build.gradle文件中
xgFlutterPlugin.startXg("1680005688", "IYIB3R2XRE22");
if (Platform.isAndroid) {
XgAndroidApi androidApi = xgFlutterPlugin.getXgAndroidApi();
//小米
// androidApi.setMiPushAppId(appId:"APP_ID");
// androidApi.setMiPushAppKey(appKey: "APPKEY");
androidApi.enableOtherPush();
androidApi.regPush();
}
ShareSDKRegister shareSDKRegister = ShareSDKRegister();
shareSDKRegister.setupWechat("wx3b269e795ed23e5f",
"64020361b8ec4c99936c0e3999a9f249", "https://hx.lotus-wallet.com/app/");
shareSDKRegister.setupFacebook(
"523308712059457", "d3a1b6377100871799d8973fbe84794a", "回乡");
SharesdkPlugin.regist(shareSDKRegister);
if (Platform.isIOS) {
LocationFlutterPlugin.setApiKey("ylW2QPlsbERkho7jOgU4GQSeawmdUIoR");
BMFMapSDK.setApiKeyAndCoordType(
'ylW2QPlsbERkho7jOgU4GQSeawmdUIoR', BMF_COORD_TYPE.COMMON);
} else if (Platform.isAndroid) {
BMFMapSDK.setCoordType(BMF_COORD_TYPE.COMMON);
}
}
EventBus eventBus = EventBus(sync: true);
class MyApp extends StatelessWidget {
final Locale? appLocale;
final bool? isFirst;
MyApp(this.appLocale, this.isFirst);
@override
Widget build(BuildContext context) {
return ScreenUtilInit(
designSize: Size(375, 812),
builder: () => MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
textTheme: TextTheme(
button: TextStyle(fontSize: 24.sp),
bodyText1: TextStyle(fontSize: 12.sp),
bodyText2: TextStyle(fontSize: 16.sp),
),
),
// locale: locale,
localeResolutionCallback: (locale, supportedLocales) {
print("locale: $locale");
print("supportedLocales: $supportedLocales");
return appLocale ?? locale
/*Locale.fromSubtags(languageCode: 'zh', countryCode: 'TW')*/;
},
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
S.delegate
],
localeListResolutionCallback:
(List<Locale>? locales, Iterable<Locale> supportedLocales) {
print("locale: ${locales![0]}");
return appLocale ?? locales![0];
},
supportedLocales: S.delegate.supportedLocales,
home: (isFirst ?? true) ? GuidePage() : LoginPage(),
// home: MainPage(),
builder: (context, widget) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaleFactor: AppUtils.textScale(context),
),
child: FlutterSmartDialog(child: widget),
);
},
onGenerateRoute: (settings) {
final String? name = settings.name;
final Function? pageContentBuilder = routers[name];
if (pageContentBuilder != null) {
final Route route = CupertinoPageRoute(
builder: (context) {
return pageContentBuilder(context,
arguments: settings.arguments);
},
settings: settings,
);
return route;
}
return MaterialPageRoute(
//未找到页面配置进入登录页
builder: (context) {
return LoginPage();
},
settings: settings,
);
},
),
);
}
}
Map<String, WidgetBuilder> routers = <String, WidgetBuilder>{
'/router/guide_Page': (context, {arguments}) => GuidePage(),
'/router/login_page': (context, {arguments}) =>
LoginPage(arguments: arguments),
'/router/main_page': (context, {arguments}) => MainPage(),
'/router/msg_page': (context, {arguments}) => MainMessagePage(),
'/router/system_msg_page': (context, {arguments}) => SystemMessagePage(),
'/router/exchange_order_details': (context, {arguments}) =>
ExchangeOrderDetailPage(),
'/router/integral_page': (context, {arguments}) => IntegralPage(),
'/router/integral_detailed_page': (context, {arguments}) =>
IntegralDetailedPage(),
'/router/mine_wallet': (context, {arguments}) => MineWalletPage(),
'/router/user_info_page': (context, {arguments}) => UserInfoPage(),
'/router/mine_card': (context, {arguments}) => MineCardPage(),
'/router/mine_card_invalid': (context, {arguments}) => MineCardInvalidPage(),
'/router/vip_card_page': (context, {arguments}) => VipCardPage(),
'/router/vip_details_page': (context, {arguments}) =>
VipDetailPage(arguments: arguments),
'/router/vip_balance': (context, {arguments}) =>
VipBalancePage(arguments: arguments),
'/router/coupons_page': (context, {arguments}) => CouponsPage(),
'/router/permission_setting': (context, {arguments}) =>
PermissionSettingPage(),
'/router/manage_address_page': (context, {arguments}) =>
ManageAddressPage(arguments: arguments),
'/router/setting_page': (context, {arguments}) => SettingPage(),
'/router/about_page': (context, {arguments}) => AboutPage(),
'/router/help_feedback_page': (context, {arguments}) => HelpFeedbackPage(),
'/router/treaty_page': (context, {arguments}) => TreatyPage(),
'/router/union_detail_page': (context, {arguments}) =>
UnionDetailsPage(arguments: arguments),
'/router/store_detail_page': (context, {arguments}) =>
StoreDetailsPage(arguments: arguments),
'/router/integral_store_page': (context, {arguments}) =>
IntegralStoreDetailsPage(
arguments: arguments,
),
'/router/exchange_order_page': (context, {arguments}) => ExchangeOrderPage(
arguments: arguments,
),
'/router/store_selector_page': (context, {arguments}) => StoreSelectorPage(),
'/router/exchange_order_success_page': (context, {arguments}) =>
ExchangeOrderSuccessPage(
arguments: arguments,
),
'/router/mine_vip_level_page': (context, {arguments}) =>
MineVipLevelPage(arguments: arguments),
'/router/exchange_history_page': (context, {arguments}) =>
ExchangeHistoryPage(),
'/router/write_off_page': (context, {arguments}) =>
WriteOffPage(arguments: arguments),
'/router/write_off_success_page': (context, {arguments}) =>
WriteOffSuccessPage(),
'/router/order_history_page': (context, {arguments}) => OrderHistoryPage(),
'/router/order_details': (context, {arguments}) =>
OrderDetailPage(arguments: arguments),
'/router/recharge_page': (context, {arguments}) => RechargePage(),
'/router/hot_article_page': (context, {arguments}) => HotArticlePage(),
'/router/address_edit_page': (context, {arguments}) => EditAddressPage(
arguments: arguments,
),
'/router/address_map_page': (context, {arguments}) => AddressMapPage(),
'/router/logistics_information_page': (context, {arguments}) =>
LogisticsInformationPage(arguments: arguments),
'/router/hot_article_details_page': (context, {arguments}) =>
HotArticleDetailsPage(),
'/router/founder_story_page': (context, {arguments}) => FounderStoryPage(),
'/router/video_playback_page': (context, {arguments}) => VideoPlaybackPage(),
'/router/roll_center_page': (context, {arguments}) => RollCenterPage(),
'/router/edit_remarks_page': (context, {arguments}) => EditRemarksPage(),
'/router/edit_name': (context, {arguments}) => EditName(
arguments: arguments,
),
'/router/location_map': (context, {arguments}) => LocationMap(
arguments: arguments,
),
// '/router/hot_article_details_page': (context, {arguments}) => HotArticleDetailsPage(),
// '/router/ui_test': (context, {arguments}) => UITest(),
};