|
@@ -53,7 +53,8 @@ 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'); |
|
@@ -72,7 +73,8 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker |
|
|
|
|
|
|
|
|
//如果登出则重新打开首页 |
|
|
//如果登出则重新打开首页 |
|
|
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"); |
|
@@ -123,7 +125,8 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker |
|
|
//app后台杀死时候的还原 |
|
|
//app后台杀死时候的还原 |
|
|
Moblink.restoreScene(_restore); |
|
|
Moblink.restoreScene(_restore); |
|
|
// 监听开始(传递监听到原生端,用户监听场景还原的数据回传回来) |
|
|
// 监听开始(传递监听到原生端,用户监听场景还原的数据回传回来) |
|
|
eventChannelSubscription = _eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError); |
|
|
|
|
|
|
|
|
eventChannelSubscription = |
|
|
|
|
|
_eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError); |
|
|
|
|
|
|
|
|
logOutSubscription = EventUtil.instance.on<LogOut>().listen((event) { |
|
|
logOutSubscription = EventUtil.instance.on<LogOut>().listen((event) { |
|
|
MobPushUtil.deleteAlias(); |
|
|
MobPushUtil.deleteAlias(); |
|
@@ -131,7 +134,8 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
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) { |
|
@@ -190,6 +194,8 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker |
|
|
} |
|
|
} |
|
|
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['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) { |
|
@@ -229,7 +235,9 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker |
|
|
), |
|
|
), |
|
|
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)), |
|
|
))); |
|
|
))); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@@ -251,6 +259,7 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker |
|
|
elevation: 0, |
|
|
elevation: 0, |
|
|
onTap: ((index) async { |
|
|
onTap: ((index) async { |
|
|
BaseTabModel model = BaseTabModel.fromJson(tabs[index]); |
|
|
BaseTabModel model = BaseTabModel.fromJson(tabs[index]); |
|
|
|
|
|
|
|
|
if (await _checkLimit(model)) { |
|
|
if (await _checkLimit(model)) { |
|
|
///避免同一个页面多次点击多次重绘 |
|
|
///避免同一个页面多次点击多次重绘 |
|
|
if (_currentIndex == index) { |
|
|
if (_currentIndex == index) { |
|
@@ -264,6 +273,7 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker |
|
|
setState(() { |
|
|
setState(() { |
|
|
_currentIndex = index; |
|
|
_currentIndex = index; |
|
|
}); |
|
|
}); |
|
|
|
|
|
EventUtil.instance.fire(model?.skipIdentifier); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}), |
|
|
}), |
|
@@ -330,7 +340,8 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker |
|
|
|
|
|
|
|
|
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...'); |
|
@@ -351,15 +362,20 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker |
|
|
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) { |
|
|
///啥也不干 |
|
|
///啥也不干 |
|
@@ -449,14 +465,17 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker |
|
|
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 |
|
@@ -478,7 +497,9 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker |
|
|
///设置定向推送 |
|
|
///设置定向推送 |
|
|
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']; |
|
@@ -534,4 +555,4 @@ abstract class LifeState<T extends StatefulWidget> extends State<T> with RouteAw |
|
|
void onResume(); |
|
|
void onResume(); |
|
|
|
|
|
|
|
|
void onPaused(); |
|
|
void onPaused(); |
|
|
} |
|
|
|
|
|
|
|
|
} |