我在flutter项目应用程序中使用firebase_dynamic_links 0.5.0。我正在使用bloc进行状态管理,并且导航出现问题。我通常在处理链接,但是当我尝试导航到另一个不起作用的页面时。我不知道为什么?
PS:我已经测试过firebase_dynamic_links example,并且可以正常工作
main() {
WidgetsFlutterBinding.ensureInitialized();
// Production code
ErrorWidget.builder = (FlutterErrorDetails details) => Container();
runApp(MyApp());
}
// Myapp类,我得到打印结果,但导航不起作用
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _authBloc = AuthBloc();
final _progressBloc = new ProgressBloc();
@override
void initState() {
super.initState();
initDynamicLinks();
}
void initDynamicLinks() async {
final PendingDynamicLinkData data =
await FirebaseDynamicLinks.instance.getInitialLink();
final Uri deepLink = data?.link;
//print("hhhhhhh" + deepLink.path);
if (deepLink != null) {
print("Link :" + deepLink.path);
// this line don't work
Navigator.pushNamed(context, '/helloworld');
}
FirebaseDynamicLinks.instance.onLink(
onSuccess: (PendingDynamicLinkData dynamicLink) async {
final Uri deepLink = dynamicLink?.link;
if (deepLink != null) {
print("Link :" + deepLink.path);
Navigator.pushNamed(context, '/helloworld');
}
}, onError: (OnLinkErrorException e) async {
print('onLinkError');
print(e.message);
});
}
@override
Widget build(BuildContext context) {
ThemeData themeData = ThemeData(
fontFamily: Constants.DEFAULT_FONT_NAME,
textTheme: Theme.of(context)
.textTheme
.apply(fontFamily: Constants.DEFAULT_FONT_NAME),
brightness: Brightness.light,
canvasColor: Colors.black12,
scaffoldBackgroundColor: Colors.white,
primaryIconTheme:
Theme.of(context).primaryIconTheme.copyWith(color: Colors.white),
accentIconTheme:
Theme.of(context).accentIconTheme.copyWith(color: Colors.white),
primaryTextTheme:
Theme.of(context).primaryTextTheme.apply(bodyColor: Colors.white),
primaryColorLight: Colors.white,
primaryColorBrightness: Brightness.light,
primarySwatch: Constants.COLOR_PRIMARY,
primaryColor: Constants.COLOR_PRIMARY,
);
var home = Stack(children: <Widget>[
RootPage(),
ProgressDialog(),
]);
return ProgressProvider(
dialog: _progressBloc,
child: AuthBlocProvider(
bloc: _authBloc,
child: StoreBlocProvider(
store: Store(),
child: RootProvider(
bloc: new RootBloc(),
child: MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
const Locale('en'), // English
const Locale('fr'), // Hebrew
],
title: 'Foodynasty',
theme: themeData,
debugShowCheckedModeBanner: false,
routes: <String, WidgetBuilder>{
'/': (BuildContext context) => home,
'/helloworld': (BuildContext context) => RestaurantShare(
restaurantId: 'test',
),
},
),
),
),
),
);
}
}
谢谢,对不起,我的英语不好。
答案 0 :(得分:0)
可能是deepLink
为空,并且if
语句中的代码未执行。您能否提供一个发送到应用程序的深层链接的示例?如果发生错误,firebase_dynamic_links
可能无法正确解析深层链接。