import 'dart:convert'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:velocity_x/velocity_x.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; class JpushMessageParse { final Map message; String subTitle; String type = '0'; JpushMessageParse(Map rawMessage) : message = Map.from(rawMessage); Future shot() async { subTitle = message['alert']; Map rawExtras = message['extras']; String androidExtra = rawExtras['cn.jpush.android.EXTRA']; if (androidExtra == null) { return; } else { Map _innerMap = jsonDecode(androidExtra); type = _innerMap['type'] ?? '0'; switch (type) { case '1': await fireAlert(subTitle); break; default: } } } Future fireAlert(String subTitle) async { await Get.dialog( CupertinoAlertDialog( title: Text('发现火灾!请立刻组织疏散人群!'), content: Column( children: [ Text(subTitle), 10.w.heightBox, Icon( CupertinoIcons.bell_fill, color: Colors.red, size: 48.w, ), ], ), actions: [ CupertinoDialogAction( child: Text('确认'), onPressed: () => Get.back(), ), ], ), barrierDismissible: false, ); } }