|
@@ -54,8 +54,7 @@ class HomePage extends StatefulWidget { |
|
|
_HomePageState createState() => _HomePageState(); |
|
|
_HomePageState createState() => _HomePageState(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
class _HomePageState extends State<HomePage> |
|
|
|
|
|
with WidgetsBindingObserver, TickerProviderStateMixin, AutomaticKeepAliveClientMixin { |
|
|
|
|
|
|
|
|
class _HomePageState extends State<HomePage> with WidgetsBindingObserver, TickerProviderStateMixin, AutomaticKeepAliveClientMixin { |
|
|
int _currentIndex = 0; |
|
|
int _currentIndex = 0; |
|
|
List<Map<String, dynamic>> _data = List(); |
|
|
List<Map<String, dynamic>> _data = List(); |
|
|
static const EventChannel _eventChannel = const EventChannel('JAVA_TO_FLUTTER'); |
|
|
static const EventChannel _eventChannel = const EventChannel('JAVA_TO_FLUTTER'); |
|
@@ -74,8 +73,7 @@ class _HomePageState extends State<HomePage> |
|
|
|
|
|
|
|
|
//如果登出则重新打开首页 |
|
|
//如果登出则重新打开首页 |
|
|
streamSubscription = EventUtil.instance.on<LogOut>().listen((event) async { |
|
|
streamSubscription = EventUtil.instance.on<LogOut>().listen((event) async { |
|
|
UserInfoModel user = |
|
|
|
|
|
await Provider.of<UserInfoNotifier>(context, listen: false).getUserInfoModel(); |
|
|
|
|
|
|
|
|
UserInfoModel user = await Provider.of<UserInfoNotifier>(context, listen: false).getUserInfoModel(); |
|
|
user.token = ''; |
|
|
user.token = ''; |
|
|
Navigator.maybePop(context); |
|
|
Navigator.maybePop(context); |
|
|
print("重启1"); |
|
|
print("重启1"); |
|
@@ -96,12 +94,17 @@ class _HomePageState extends State<HomePage> |
|
|
try { |
|
|
try { |
|
|
WidgetsBinding.instance.addObserver(this); |
|
|
WidgetsBinding.instance.addObserver(this); |
|
|
|
|
|
|
|
|
|
|
|
// 监听开始(传递监听到原生端,用户监听场景还原的数据回传回来) |
|
|
|
|
|
eventChannelSubscription = _eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError); |
|
|
|
|
|
|
|
|
///渲染完第一帧后调用 |
|
|
///渲染完第一帧后调用 |
|
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) { |
|
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) { |
|
|
int delay = ((num.tryParse(AppConfigModel.appStartDelay) ?? 0.5) * 1000).toInt(); |
|
|
int delay = ((num.tryParse(AppConfigModel.appStartDelay) ?? 0.5) * 1000).toInt(); |
|
|
print("延时" + AppConfigModel.appStartDelay.toString()); |
|
|
print("延时" + AppConfigModel.appStartDelay.toString()); |
|
|
Timer(Duration(milliseconds: delay), () { |
|
|
Timer(Duration(milliseconds: delay), () { |
|
|
NativeUtil.notifyInitSuccess(); |
|
|
NativeUtil.notifyInitSuccess(); |
|
|
|
|
|
//app后台杀死时候的还原 |
|
|
|
|
|
Moblink.restoreScene(_restore); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
@@ -127,21 +130,13 @@ class _HomePageState extends State<HomePage> |
|
|
|
|
|
|
|
|
}*/ |
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 监听开始(传递监听到原生端,用户监听场景还原的数据回传回来) |
|
|
|
|
|
eventChannelSubscription = |
|
|
|
|
|
_eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError); |
|
|
|
|
|
|
|
|
|
|
|
//app后台杀死时候的还原 |
|
|
|
|
|
Moblink.restoreScene(_restore); |
|
|
|
|
|
logOutSubscription = EventUtil.instance.on<LogOut>().listen((event) { |
|
|
logOutSubscription = EventUtil.instance.on<LogOut>().listen((event) { |
|
|
MobPushUtil.deleteAlias(); |
|
|
MobPushUtil.deleteAlias(); |
|
|
SharedPreferencesUtil.setStringValue(Constants.isSetTag, "0"); |
|
|
SharedPreferencesUtil.setStringValue(Constants.isSetTag, "0"); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
MobPushUtil.addPushReceiver(); |
|
|
MobPushUtil.addPushReceiver(); |
|
|
loginSubscription = |
|
|
|
|
|
EventUtil.instance.on<LoginSuccessEvent>().listen((event) async { |
|
|
|
|
|
|
|
|
loginSubscription = EventUtil.instance.on<LoginSuccessEvent>().listen((event) async { |
|
|
setAlias(); |
|
|
setAlias(); |
|
|
}); |
|
|
}); |
|
|
} catch (e, s) { |
|
|
} catch (e, s) { |
|
@@ -202,7 +197,7 @@ class _HomePageState extends State<HomePage> |
|
|
List<Widget> contentWidgets = tabs.map((item) { |
|
|
List<Widget> contentWidgets = tabs.map((item) { |
|
|
BaseTabModel model = BaseTabModel.fromJson(item); |
|
|
BaseTabModel model = BaseTabModel.fromJson(item); |
|
|
//首页底部创建的item,把抖券判断置true |
|
|
//首页底部创建的item,把抖券判断置true |
|
|
item['is_bottom_video']=true; |
|
|
|
|
|
|
|
|
item['is_bottom_video'] = true; |
|
|
return PageFactory.create(model.skipIdentifier, item); |
|
|
return PageFactory.create(model.skipIdentifier, item); |
|
|
}).toList(); |
|
|
}).toList(); |
|
|
if (_currentIndex >= contentWidgets.length) { |
|
|
if (_currentIndex >= contentWidgets.length) { |
|
@@ -210,13 +205,12 @@ class _HomePageState extends State<HomePage> |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return WillPopScope( |
|
|
return WillPopScope( |
|
|
onWillPop: () async{ |
|
|
|
|
|
|
|
|
onWillPop: () async { |
|
|
print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>HomepageBack>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); |
|
|
print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>HomepageBack>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); |
|
|
EventUtil.instance.fire("HomepageSignOut"); |
|
|
EventUtil.instance.fire("HomepageSignOut"); |
|
|
// 退出app |
|
|
// 退出app |
|
|
// await SystemChannels.platform.invokeMethod('SystemNavigator.pop'); |
|
|
// await SystemChannels.platform.invokeMethod('SystemNavigator.pop'); |
|
|
return true; |
|
|
return true; |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
child: Scaffold( |
|
|
child: Scaffold( |
|
|
body: IndexedStack( |
|
|
body: IndexedStack( |
|
@@ -252,9 +246,7 @@ class _HomePageState extends State<HomePage> |
|
|
), |
|
|
), |
|
|
title: Text( |
|
|
title: Text( |
|
|
model.name, |
|
|
model.name, |
|
|
style: TextStyle( |
|
|
|
|
|
fontSize: 11, |
|
|
|
|
|
color: HexColor.fromHex(_currentIndex == i ? chooseColor : textColor)), |
|
|
|
|
|
|
|
|
style: TextStyle(fontSize: 11, color: HexColor.fromHex(_currentIndex == i ? chooseColor : textColor)), |
|
|
))); |
|
|
))); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@@ -357,8 +349,7 @@ class _HomePageState extends State<HomePage> |
|
|
|
|
|
|
|
|
Future<bool> _checkLimit(BaseTabModel model) async { |
|
|
Future<bool> _checkLimit(BaseTabModel model) async { |
|
|
if (model.requiredLogin == '1') { |
|
|
if (model.requiredLogin == '1') { |
|
|
UserInfoModel user = |
|
|
|
|
|
await Provider.of<UserInfoNotifier>(context, listen: false).getUserInfoModel(); |
|
|
|
|
|
|
|
|
UserInfoModel user = await Provider.of<UserInfoNotifier>(context, listen: false).getUserInfoModel(); |
|
|
print(user.toString()); |
|
|
print(user.toString()); |
|
|
if (user?.token == null || user.token == '') { |
|
|
if (user?.token == null || user.token == '') { |
|
|
print('need login...'); |
|
|
print('need login...'); |
|
@@ -379,20 +370,15 @@ class _HomePageState extends State<HomePage> |
|
|
await Future.delayed(Duration(milliseconds: 1000), () async { |
|
|
await Future.delayed(Duration(milliseconds: 1000), () async { |
|
|
// 通知弹窗 |
|
|
// 通知弹窗 |
|
|
///每打开5次检查一次权限 |
|
|
///每打开5次检查一次权限 |
|
|
String showNotiPermissionTime = await SharedPreferencesUtil.getStringValue( |
|
|
|
|
|
Constants.showNotiPermissionTime, |
|
|
|
|
|
defaultVal: "5"); |
|
|
|
|
|
|
|
|
String showNotiPermissionTime = await SharedPreferencesUtil.getStringValue(Constants.showNotiPermissionTime, defaultVal: "5"); |
|
|
int timer = int.tryParse(showNotiPermissionTime) ?? 0; |
|
|
int timer = int.tryParse(showNotiPermissionTime) ?? 0; |
|
|
if (timer % 5 == 0) { |
|
|
if (timer % 5 == 0) { |
|
|
timer++; |
|
|
timer++; |
|
|
SharedPreferencesUtil.setStringValue( |
|
|
|
|
|
Constants.showNotiPermissionTime, timer.toString()); |
|
|
|
|
|
|
|
|
SharedPreferencesUtil.setStringValue(Constants.showNotiPermissionTime, timer.toString()); |
|
|
if (!await Permission.storage.isGranted) { |
|
|
if (!await Permission.storage.isGranted) { |
|
|
await NotificationSettingDialogNew.show(context); |
|
|
await NotificationSettingDialogNew.show(context); |
|
|
} |
|
|
} |
|
|
String notificationAgree = await SharedPreferencesUtil.getStringValue( |
|
|
|
|
|
Constants.notificationAgree, |
|
|
|
|
|
defaultVal: "0"); |
|
|
|
|
|
|
|
|
String notificationAgree = await SharedPreferencesUtil.getStringValue(Constants.notificationAgree, defaultVal: "0"); |
|
|
|
|
|
|
|
|
if (notificationAgree == "1" && await Permission.notification.isGranted) { |
|
|
if (notificationAgree == "1" && await Permission.notification.isGranted) { |
|
|
///啥也不干 |
|
|
///啥也不干 |
|
@@ -483,17 +469,14 @@ class _HomePageState extends State<HomePage> |
|
|
void showAlert(String text, BuildContext context) { |
|
|
void showAlert(String text, BuildContext context) { |
|
|
showDialog( |
|
|
showDialog( |
|
|
context: context, |
|
|
context: context, |
|
|
builder: (BuildContext context) => CupertinoAlertDialog( |
|
|
|
|
|
title: new Text("提示"), |
|
|
|
|
|
content: new Text(text), |
|
|
|
|
|
actions: <Widget>[ |
|
|
|
|
|
new FlatButton( |
|
|
|
|
|
child: new Text("OK"), |
|
|
|
|
|
onPressed: () { |
|
|
|
|
|
Navigator.of(context).pop(); |
|
|
|
|
|
}, |
|
|
|
|
|
) |
|
|
|
|
|
])); |
|
|
|
|
|
|
|
|
builder: (BuildContext context) => CupertinoAlertDialog(title: new Text("提示"), content: new Text(text), actions: <Widget>[ |
|
|
|
|
|
new FlatButton( |
|
|
|
|
|
child: new Text("OK"), |
|
|
|
|
|
onPressed: () { |
|
|
|
|
|
Navigator.of(context).pop(); |
|
|
|
|
|
}, |
|
|
|
|
|
) |
|
|
|
|
|
])); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@override |
|
|
@override |
|
@@ -515,9 +498,7 @@ class _HomePageState extends State<HomePage> |
|
|
///设置定向推送 |
|
|
///设置定向推送 |
|
|
void setAlias() async { |
|
|
void setAlias() async { |
|
|
///如果没有开启通知则设置别名 |
|
|
///如果没有开启通知则设置别名 |
|
|
if (await SharedPreferencesUtil.getStringValue(Constants.notificationAgree, |
|
|
|
|
|
defaultVal: "0") == |
|
|
|
|
|
"1") { |
|
|
|
|
|
|
|
|
if (await SharedPreferencesUtil.getStringValue(Constants.notificationAgree, defaultVal: "0") == "1") { |
|
|
UserInfoModel userInfo = UserInfoNotifier?.staitcUserInfo; |
|
|
UserInfoModel userInfo = UserInfoNotifier?.staitcUserInfo; |
|
|
var setting = await NativeUtil.getSetting(); |
|
|
var setting = await NativeUtil.getSetting(); |
|
|
String masterId = setting['master_id']; |
|
|
String masterId = setting['master_id']; |
|
|