修复上架问题:应用内消息推送按钮无法正常使用
This commit is contained in:
parent
b60a50a08e
commit
aa421496a5
@ -1,7 +1,11 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
import 'package:star_lock/flavors.dart';
|
import 'package:star_lock/flavors.dart';
|
||||||
import 'package:star_lock/mine/mineSet/mineSet/mineSet_logic.dart';
|
import 'package:star_lock/mine/mineSet/mineSet/mineSet_logic.dart';
|
||||||
import '../../../appRouters.dart';
|
import '../../../appRouters.dart';
|
||||||
@ -18,7 +22,7 @@ class MineSetPage extends StatefulWidget {
|
|||||||
State<MineSetPage> createState() => _MineSetPageState();
|
State<MineSetPage> createState() => _MineSetPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MineSetPageState extends State<MineSetPage> {
|
class _MineSetPageState extends State<MineSetPage> with WidgetsBindingObserver {
|
||||||
final logic = Get.put(MineSetLogic());
|
final logic = Get.put(MineSetLogic());
|
||||||
final state = Get.find<MineSetLogic>().state;
|
final state = Get.find<MineSetLogic>().state;
|
||||||
|
|
||||||
@ -26,11 +30,25 @@ class _MineSetPageState extends State<MineSetPage> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
|
WidgetsBinding.instance.addObserver(this);
|
||||||
|
|
||||||
logic.userSettingsInfoRequest();
|
logic.userSettingsInfoRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||||
|
super.didChangeAppLifecycleState(state);
|
||||||
|
if (state == AppLifecycleState.resumed) {
|
||||||
|
// 应用从后台返回前台
|
||||||
|
// 在这里执行相应的操作
|
||||||
|
_checkNotificationPermission();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
_checkNotificationPermission();
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: AppColors.mainBackgroundColor,
|
backgroundColor: AppColors.mainBackgroundColor,
|
||||||
appBar: TitleAppBar(
|
appBar: TitleAppBar(
|
||||||
@ -371,8 +389,45 @@ class _MineSetPageState extends State<MineSetPage> {
|
|||||||
thumbColor: CupertinoColors.white,
|
thumbColor: CupertinoColors.white,
|
||||||
value: state.isPushNotification.value,
|
value: state.isPushNotification.value,
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
state.isPushNotification.value = !state.isPushNotification.value;
|
// state.isPushNotification.value = !state.isPushNotification.value;
|
||||||
|
openAppSettings();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _checkNotificationPermission() async {
|
||||||
|
bool notificationEnabled = false;
|
||||||
|
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
notificationEnabled = await state.flutterLocalNotificationsPlugin
|
||||||
|
.resolvePlatformSpecificImplementation<
|
||||||
|
AndroidFlutterLocalNotificationsPlugin>()
|
||||||
|
?.areNotificationsEnabled() ??
|
||||||
|
false;
|
||||||
|
} else if (Platform.isIOS) {
|
||||||
|
notificationEnabled = await state.flutterLocalNotificationsPlugin
|
||||||
|
.resolvePlatformSpecificImplementation<
|
||||||
|
IOSFlutterLocalNotificationsPlugin>()
|
||||||
|
?.requestPermissions(
|
||||||
|
alert: true,
|
||||||
|
badge: true,
|
||||||
|
sound: true,
|
||||||
|
) ??
|
||||||
|
false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (notificationEnabled) {
|
||||||
|
print('Notifications are enabled');
|
||||||
|
state.isPushNotification.value = true;
|
||||||
|
} else {
|
||||||
|
print('Notifications are disabled');
|
||||||
|
state.isPushNotification.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
WidgetsBinding.instance.removeObserver(this);
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:star_lock/mine/mineSet/mineSet/userSettingInfoEntity.dart';
|
import 'package:star_lock/mine/mineSet/mineSet/userSettingInfoEntity.dart';
|
||||||
|
|
||||||
@ -13,4 +14,6 @@ class MineSetState {
|
|||||||
var hideExpiredAccessFlag = 2.obs; //隐藏无效开锁
|
var hideExpiredAccessFlag = 2.obs; //隐藏无效开锁
|
||||||
var currentLanguage = "".obs; //隐藏无效开锁
|
var currentLanguage = "".obs; //隐藏无效开锁
|
||||||
|
|
||||||
|
late FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
|
||||||
|
FlutterLocalNotificationsPlugin();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -141,6 +141,7 @@ dependencies:
|
|||||||
flutter_slidable: ^3.0.1
|
flutter_slidable: ^3.0.1
|
||||||
audio_service: ^0.18.12
|
audio_service: ^0.18.12
|
||||||
app_settings: ^5.1.1
|
app_settings: ^5.1.1
|
||||||
|
flutter_local_notifications: ^17.0.0
|
||||||
|
|
||||||
system_settings: ^2.0.0
|
system_settings: ^2.0.0
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user