Browse Source

0506 首页底部按钮添加点击事件通知控制抖券的播放

tags/0.0.16+1
23028876916@qq.com 3 years ago
parent
commit
ed07cee5ff
1 changed files with 40 additions and 19 deletions
  1. +40
    -19
      lib/pages/home_page/home_page.dart

+ 40
- 19
lib/pages/home_page/home_page.dart View File

@@ -53,7 +53,8 @@ class HomePage extends StatefulWidget {
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> with WidgetsBindingObserver, TickerProviderStateMixin, AutomaticKeepAliveClientMixin {
class _HomePageState extends State<HomePage>
with WidgetsBindingObserver, TickerProviderStateMixin, AutomaticKeepAliveClientMixin {
int _currentIndex = 0;
List<Map<String, dynamic>> _data = List();
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 {
UserInfoModel user = await Provider.of<UserInfoNotifier>(context, listen: false).getUserInfoModel();
UserInfoModel user =
await Provider.of<UserInfoNotifier>(context, listen: false).getUserInfoModel();
user.token = '';
Navigator.maybePop(context);
print("重启1");
@@ -123,7 +125,8 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker
//app后台杀死时候的还原
Moblink.restoreScene(_restore);
// 监听开始(传递监听到原生端,用户监听场景还原的数据回传回来)
eventChannelSubscription = _eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError);
eventChannelSubscription =
_eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError);

logOutSubscription = EventUtil.instance.on<LogOut>().listen((event) {
MobPushUtil.deleteAlias();
@@ -131,7 +134,8 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker
});

MobPushUtil.addPushReceiver();
loginSubscription = EventUtil.instance.on<LoginSuccessEvent>().listen((event) async {
loginSubscription =
EventUtil.instance.on<LoginSuccessEvent>().listen((event) async {
setAlias();
});
} catch (e, s) {
@@ -190,6 +194,8 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker
}
List<Widget> contentWidgets = tabs.map((item) {
BaseTabModel model = BaseTabModel.fromJson(item);
//首页底部创建的item,把抖券判断置true
item['is_bottom_video']=true;
return PageFactory.create(model.skipIdentifier, item);
}).toList();
if (_currentIndex >= contentWidgets.length) {
@@ -229,7 +235,9 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker
),
title: Text(
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,
onTap: ((index) async {
BaseTabModel model = BaseTabModel.fromJson(tabs[index]);

if (await _checkLimit(model)) {
///避免同一个页面多次点击多次重绘
if (_currentIndex == index) {
@@ -264,6 +273,7 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker
setState(() {
_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 {
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());
if (user?.token == null || user.token == '') {
print('need login...');
@@ -351,15 +362,20 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker
await Future.delayed(Duration(milliseconds: 1000), () async {
// 通知弹窗
///每打开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;
if (timer % 5 == 0) {
timer++;
SharedPreferencesUtil.setStringValue(Constants.showNotiPermissionTime, timer.toString());
SharedPreferencesUtil.setStringValue(
Constants.showNotiPermissionTime, timer.toString());
if (!await Permission.storage.isGranted) {
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) {
///啥也不干
@@ -449,14 +465,17 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker
void showAlert(String text, BuildContext context) {
showDialog(
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
@@ -478,7 +497,9 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker
///设置定向推送
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;
var setting = await NativeUtil.getSetting();
String masterId = setting['master_id'];
@@ -534,4 +555,4 @@ abstract class LifeState<T extends StatefulWidget> extends State<T> with RouteAw
void onResume();

void onPaused();
}
}

Loading…
Cancel
Save