android - Flutter 小部件未在通知单击时呈现
问题描述
我正在使用firebase_messaging和flutter_local_notifications库来通知一切工作正常。但是在 Android 中,如果从应用程序堆栈中删除应用程序(从最近的 Activity 中删除幻灯片)而不是收到通知并单击它,则小部件无法正确呈现,按钮导航、应用程序栏、文本正在消失。
@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (_, constraints) {
return OrientationBuilder(builder: (_, orientation) {
SizeConfig().init(constraints, orientation);
return MultiBlocProvider(
providers: [
BlocProvider(create: (_)=>_mainAppBarBloc),
BlocProvider(create: (_) => _hadyahBloc),
],
child:MultiBlocListener(
listeners: [
BlocListener<HadyahBloc,HadyahState>(
listener: (_,state){
state.whenPartial(
getLanguage: (s){
var locale = _hadyahBloc.changeLanguage(s.language);
setLocale(locale);
},
);
},
),
],
child: MaterialApp(
key: _mKey,
navigatorObservers: [
sl<FirebaseAnalyticsService>().getObserver(),
],
builder: (context,_){
return Scaffold(
key: _scaffoldkey,
body: Container(
color: Colors.white,
child: ExtendedNavigator<Router>(
router: Router(),
key: navigatorKey,
initialRoute: Routes.screenNavigatorHandler,
),
),
);
},
locale: _locale,
supportedLocales: [
Locale('en','GB'),//english united kingdom
Locale('ar','SA')// arabic
],
localizationsDelegates: [
Localization.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate
],
localeResolutionCallback: (Locale locale, Iterable<Locale> supportedLocales) {
if (locale == null) {
return supportedLocales.first;
}
for (Locale supportedLocale in supportedLocales) {
if (supportedLocale.languageCode == locale.languageCode ||
supportedLocale.countryCode == locale.countryCode) {
return supportedLocale;
}
}
return supportedLocales.first;
},
debugShowCheckedModeBanner: false,
title: 'App',
theme: ThemeData(
cupertinoOverrideTheme: CupertinoThemeData(
primaryColor: colorPrimary,
),
accentColor: Colors.white,
appBarTheme:
AppBarTheme(textTheme: TextTheme(title: appBarTextStyle)),
primarySwatch: colorWhite,
dialogTheme: DialogTheme(
titleTextStyle: textStyleDisplay2,
contentTextStyle: body1TextStyle,
),
textTheme: TextTheme(
title: appBarTextStyle,
body1: body1TextStyle,
body2: body2TextStyle,
button: buttonTextStyle,
),
inputDecorationTheme: InputDecorationTheme(
border: inputFocusedBorder,
isDense: true,
alignLabelWithHint: true,
floatingLabelBehavior: FloatingLabelBehavior.never,
focusedBorder: inputFocusedBorder,
enabledBorder: inputEnabledBorder,
errorBorder: errorFocusedBorder,
focusedErrorBorder: errorFocusedBorder,
errorStyle: errorLabelStyle,
labelStyle: inputLabelTextStyle
)
),
onGenerateRoute: Router().onGenerateRoute,
navigatorKey: navigatorKey,
initialRoute: Routes.screenNavigatorHandler,
)
)
);
});
});
}
final connector = createPushConnector();
Future<void> configurePushConnector(HadyahBloc bloc)async{
try{
connector.configure(
onLaunch: _onLaunch,
onResume: _onResume,
onMessage: _onMessage,
onBackgroundMessage: _onMessage,
);
connector.token.addListener((){
var token=connector.token.value;
if(token!=null){
bloc.setFCMToken(token);
}
print('Token ${connector.token.value}');
});
connector.requestNotificationPermissions();
}catch(e){
print(e);
}
}
void _navigateToPage(Map<String,dynamic> notificationData)async{
try{
final platform=Theme.of(_mKey.currentContext).platform;
if(platform==TargetPlatform.android){
if(notificationData['data']['type']==ORDER_STATUS_UPDATED){
ExtendedNavigator.ofRouter<Router>().pushNamed(
Routes.trackOrderPage,
arguments: int.parse(notificationData['data']['order_id'])
);
}
}else if(platform==TargetPlatform.iOS){
if(notificationData['type']==ORDER_STATUS_UPDATED){
print('type orn ${notificationData['type']}');
ExtendedNavigator.ofRouter<Router>().pushNamed(
Routes.trackOrderPage,
arguments:notificationData['order_id']
);
}else{
print(' else type orn ${notificationData['type']}');
}
}
}catch(e){
print('notification error $e');
}
}
Future<dynamic> _onLaunch(Map<String,dynamic>
notificationData)async{
await Future.delayed(Duration(milliseconds: 1500));
_navigateToPage(notificationData);
return Future.value();
}
解决方案
推荐阅读
- c# - ORA-12154 使用连接字符串时
- javascript - 使用 Javascript 和 C# Web 将文件转换为二进制文件
- javascript - 检查localStorage中是否有值,如果没有显示替代消息(Javascript)
- ruby-on-rails - Rails 视图中的 Ruby 模块函数,手动渲染
- selenium - Selenium 脚本没有在 Jenkins 上的 Chrome 上运行,但它可以在 eclipse 中运行
- angular - Angular XLSX:包含小数的单元格文本在将 excel 转换为 JSON 对象时给了我一些随机数
- java - 无法使用 Java 流()映射级联列表的字段
- node.js - Next.js 应用程序在创建图像后无法正常工作
- android - 使用 Json Api 的颤振图表
- html - 如何在具有纵横比的 div 中设置居中文本?