Explorar el Código

1.更新消息通知弹窗显示

tags/0.0.15+6
“yanghuaxuan” hace 3 años
padre
commit
535a831e1d
Se han modificado 5 ficheros con 199 adiciones y 30 borrados
  1. +1
    -1
      example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java
  2. +0
    -4
      lib/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart
  3. +140
    -0
      lib/dialog/notification_dialog/notification_dialog.dart
  4. +51
    -23
      lib/pages/home_page/home_page.dart
  5. +7
    -2
      lib/utils/contants.dart

+ 1
- 1
example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java Ver fichero

@@ -159,7 +159,7 @@ public class MainActivity extends FlutterActivity implements ZhiyingFlutterCommN
Map map = new HashMap();
///测试
map.put("domain", "http://inapi.izhyin.cn/");//"http://120.76.175.204:8989");http://47.114.51.254:80 http://inapi.izhyin.cn/
map.put("master_id", "123456");
map.put("master_id", "22255132");
map.put("secret_key", "123456");

///正式


+ 0
- 4
lib/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart Ver fichero

@@ -237,10 +237,6 @@ class NotificationSettingDialogNew extends StatelessWidget {
if (!await Permission.storage.isGranted) {
newPermissModels.add(storagePermissModel);
}

if (!await Permission.notification.isGranted) {
newPermissModels.add(notificationPermissModel);
}
} else {
newPermissModels = permissModels;
}


+ 140
- 0
lib/dialog/notification_dialog/notification_dialog.dart Ver fichero

@@ -0,0 +1,140 @@
import 'package:flutter/material.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

class NotificationDialog extends StatefulWidget {
final bool isGranted;

const NotificationDialog({Key key, this.isGranted = false}) : super(key: key);

@override
_NotificationDialogState createState() => _NotificationDialogState();
}

class _NotificationDialogState extends State<NotificationDialog> {
String tipString = "";

@override
void initState() {
if (!widget?.isGranted) {
tipString = "系统检查到您还未开启通知权限,点击确认开启后会跳转到系统设置";
}
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.transparent,
body: Container(
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: 265,
padding: EdgeInsets.all(20),
// height: 382,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
),
child: Column(
children: <Widget>[
CachedNetworkImage(
imageUrl: "https://alipic.lanhuapp.com/SketchPng0b9277cdefb9a187ab3bb380a2a340ce40f7e7c31368ed08d30745bb140def63",
height: 73,
width: 70,
fit: BoxFit.fitHeight,
),
SizedBox(
height: 10,
),
Text(
"开启消息通知",
style: TextStyle(fontSize: 15, color: HexColor.fromHex("#FF4F39")),
),
SizedBox(
height: 10,
),
Text(
"获取实时获取最新消息、收益、粉丝提醒、优惠信息等",
style: TextStyle(fontSize: 13, color: HexColor.fromHex("#999999")),
),
SizedBox(
width: 10,
),
Text(
tipString ?? "",
style: TextStyle(fontSize: 12, color: HexColor.fromHex("#FF4F39")),
),
SizedBox(
height: 20,
),
Row(
children: [
SizedBox(
width: 10,
),

Expanded(
child: GestureDetector(
onTap: () async {
Navigator.pop(context, true);
},
child: Container(
margin: EdgeInsets.only(top: 10, bottom: 10),
height: 38,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
gradient: LinearGradient(
begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [HexColor.fromHex("#FFFF5632"), HexColor.fromHex("#FFFF4242")])),
child: Center(
child: Text(
"确认开启",
style: TextStyle(color: Colors.white, fontSize: 13),
))),
),
),
SizedBox(
width: 8,
),
Expanded(
child: GestureDetector(
onTap: () async {
Navigator.pop(context, false);
},
child: Container(
margin: EdgeInsets.only(top: 10, bottom: 10),
height: 38,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
gradient: LinearGradient(
begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [HexColor.fromHex("#D6D6D6"), HexColor.fromHex("#D6D6D6")])),
child: Center(
child: Text(
"暂时关闭",
style: TextStyle(color: Colors.white, fontSize: 13),
))),
),
),
SizedBox(
width: 10,
)
],
)
],
),
),
GestureDetector(
onTap: () {
Navigator.pop(context, false);
},
child: Container(alignment: Alignment.center, margin: EdgeInsets.only(top: 10), child: CloseButton(color: HexColor.fromHex("#FFFFFF"))),
)
],
),
),
);
}
}

+ 51
- 23
lib/pages/home_page/home_page.dart Ver fichero

@@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:convert' as convert;
import 'dart:io';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
@@ -13,6 +14,7 @@ import 'package:provider/provider.dart';
import 'package:zhiying_base_widget/dialog/global_dialog/advertising_dialog/advertising_dialog.dart';
import 'package:zhiying_base_widget/dialog/global_dialog/intellect_search_goods_dialog/intellect_create.dart';
import 'package:zhiying_base_widget/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart';
import 'package:zhiying_base_widget/dialog/notification_dialog/notification_dialog.dart';
import 'package:zhiying_base_widget/dialog/tip_dialog/tip_dialog.dart';
import 'package:zhiying_base_widget/models/app_config_model.dart';
import 'package:zhiying_base_widget/pages/custom_page/event/reload_event.dart';
@@ -58,7 +60,6 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker
StreamSubscription streamSubscription;

StreamSubscription reloadSubscription;
StreamSubscription aliasSubscription;
StreamSubscription logOutSubscription;
StreamSubscription loginSubscription;

@@ -111,6 +112,9 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker

Moblink.uploadPrivacyPermissionStatus(1, (bool success) {});
SharesdkPlugin.uploadPrivacyPermissionStatus(1, (bool success) {});

///设置推送标识
setAlias();
// 是安卓系统,Android场景还原的实现
/*if (defaultTargetPlatform == TargetPlatform.android) {

@@ -121,30 +125,14 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker
// 监听开始(传递监听到原生端,用户监听场景还原的数据回传回来)
eventChannelSubscription = _eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError);

MobPushUtil.addPushReceiver();
aliasSubscription = EventUtil.instance.on<LoginSuccessEvent>().listen((event) async {
UserInfoModel userInfo = UserInfoNotifier?.staitcUserInfo;
var setting = await NativeUtil.getSetting();
String masterId = setting['master_id'];
Logger.log("我的Alias: " + masterId + "_" + userInfo?.userId);
if (!EmptyUtil.isEmpty(userInfo.userId) && !EmptyUtil.isEmpty(masterId)) {
MobPushUtil.setAlias(masterId + "_" + userInfo.userId);
}
});

logOutSubscription = EventUtil.instance.on<LogOut>().listen((event) {
MobPushUtil.deleteAlias();
SharedPreferencesUtil.setStringValue(Constants.isSetTag, "0");
});

MobPushUtil.addPushReceiver();
loginSubscription = EventUtil.instance.on<LoginSuccessEvent>().listen((event) async {
UserInfoModel userInfo = UserInfoNotifier?.staitcUserInfo;
var setting = await NativeUtil.getSetting();
String masterId = setting['master_id'];
Logger.log("我的Alias: " + masterId + "_" + userInfo?.userId);
if (!EmptyUtil.isEmpty(userInfo.userId) && !EmptyUtil.isEmpty(masterId)) {
MobPushUtil.setAlias(masterId + "_" + userInfo.userId);
}
setAlias();
});
} catch (e, s) {
print(e);
@@ -170,7 +158,6 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker
WidgetsBinding.instance.removeObserver(this);
streamSubscription.cancel();
reloadSubscription?.cancel();
aliasSubscription?.cancel();
logOutSubscription?.cancel();
loginSubscription?.cancel();
eventChannelSubscription?.cancel();
@@ -362,12 +349,36 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker
String showNotiPermissionTime = await SharedPreferencesUtil.getStringValue(Constants.showNotiPermissionTime, defaultVal: "5");
int timer = int.tryParse(showNotiPermissionTime) ?? 0;
if (timer % 5 == 0) {
if (!await Permission.notification.isGranted || !await Permission.storage.isGranted) {
timer++;
SharedPreferencesUtil.setStringValue(Constants.showNotiPermissionTime, timer.toString());
if (!await Permission.storage.isGranted) {
await NotificationSettingDialogNew.show(context);
}
String notificationAgree = await SharedPreferencesUtil.getStringValue(Constants.notificationAgree, defaultVal: "0");

if (notificationAgree == "1" && await Permission.notification.isGranted) {
///啥也不干
} else {
if (notificationAgree == "0" || !await Permission.notification.isGranted) {
bool isGranted = await Permission.notification.isGranted;
var result = await showDialog(
context: context,
child: NotificationDialog(
isGranted: isGranted,
));
if (result != null && result) {
SharedPreferencesUtil.setStringValue(Constants.notificationAgree, "1");
if (!await Permission.notification.isGranted) {
if (Platform.isIOS) {
openAppSettings();
} else {
await NativeUtil.openAppSettings();
}
}
}
}
}
}
timer++;
SharedPreferencesUtil.setStringValue(Constants.showNotiPermissionTime, timer.toString());

// 活动弹窗
await AdvertisingDialog.show(context);
@@ -458,4 +469,21 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker
@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;

///设置定向推送
void setAlias() async {
///如果没有开启通知则设置别名
if (await SharedPreferencesUtil.getStringValue(Constants.notificationAgree, defaultVal: "0") == "1") {
UserInfoModel userInfo = UserInfoNotifier?.staitcUserInfo;
var setting = await NativeUtil.getSetting();
String masterId = setting['master_id'];
Logger.log("我的Alias: " + masterId + "_" + userInfo?.userId);
if (!EmptyUtil.isEmpty(userInfo.userId) && !EmptyUtil.isEmpty(masterId)) {
print("设置标签" + masterId + "_" + userInfo.userId);
await MobPushUtil.restartPush();
await MobPushUtil.setAlias(masterId + "_" + userInfo.userId);
SharedPreferencesUtil.setStringValue(Constants.isSetTag, "1");
}
}
}
}

+ 7
- 2
lib/utils/contants.dart Ver fichero

@@ -30,7 +30,12 @@ class Constants {
//==============================版本号,控制引导页显示===================================
static String versionNumber = "versionNumber";


///masterId
static String masterId="sp_master_id";
static String masterId = "sp_master_id";

static String notificationAgree = "notificationAgree";

///是否设置推送tag
static String isSetTag= "isSetTag";

}

Cargando…
Cancelar
Guardar