Error: Could not find the correct Provider<DashboardBloc> above this DashboardPage Widget - FLUTTER
Error: Could not find the correct Provider<DashboardBloc> above this DashboardPage Widget - FLUTTER
我是 flutter 的新手,我试图在获得用户身份验证后允许我的应用程序移动到 DashboardPage,但我收到此错误:无法在此 DashboardPage 小部件上方找到正确的提供程序
发生这种情况是因为您使用的 BuildContext
不包括提供商
任您选择。
这是我的代码 auth_page 在这两种情况下,代码和生物识别身份验证必须始终指向 DashboardPage() :
class AuthPage extends StatelessWidget {
static String routeName = '/fingerprint';
Future<void> localAuth(BuildContext context) async {
final localAuth = LocalAuthentication();
final didAuthenticate = await localAuth.authenticateWithBiometrics(
localizedReason: 'Please authenticate');
if (didAuthenticate) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => DashboardPage()),
);
}
}
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
centerTitle: true,
),
body: Padding(
padding: EdgeInsets.all(32),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
buildPinScreen(context),
SizedBox(height: 24),
SizedBox(height: 24),
],
),
),
),
);
Widget buildPinScreen(BuildContext context) => buildButton(
text: 'UnLock',
icon: Icons.lock_open,
onClicked: () async {
screenLock(context: context, correctString: '1234',
canCancel: true,
didUnlocked: (){
Navigator.push(
context,
MaterialPageRoute(builder: (context) => DashboardPage()),
);
},
customizedButtonTap: () async {
await localAuth(context);
},
didOpened: () async {
await localAuth(context);
},
);
}
);
这是我的代码 class route_configuration :
final router = FluroRouter();
class RouteConfiguration {
static Future<void> register() async {
// Register the routes
router.define("/", handler: rootHandler);
router.define(AssetFormScreen.routeName, handler: assetFormHandler);
router.define(AssetTransferScreen.routeName, handler: assetTransferHandler);
router.define(ShareAddressScreen.routeName, handler: shareAddressHandler);
router.define(DashboardPage.routeName, handler: dashboardHandler);
}
}
这是我的代码 class route_handlers :
var rootHandler = Handler(
type: HandlerType.route,
handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
return MultiBlocProvider(
providers: [
BlocProvider<MainBloc>(
create: (_) => MainBloc(accountRepository: accountRepository),
),
BlocProvider<NavigationBloc>(
create: (_) => NavigationBloc(tabs[0]),
),
],
child: MainScreen(),
);
},
);
var assetTransferHandler = Handler(
handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
final asset = context?.settings?.arguments;
if (asset is! AlgorandStandardAsset) return null;
return BlocProvider(
create: (_) =>
AssetTransferBloc(accountRepository: accountRepository)..start(asset),
child: AssetTransferScreen(),
);
},
);
var assetFormHandler = Handler(
handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
return BlocProvider<AssetFormBloc>(
create: (_) => AssetFormBloc(accountRepository: accountRepository),
child: AssetFormScreen(),
);
},
);
var shareAddressHandler = Handler(
handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
final address = params['address']?[0] ?? '';
return BlocProvider<AssetFormBloc>(
create: (_) => AssetFormBloc(accountRepository: accountRepository),
child: ShareAddressScreen(
address: address,
),
);
},
);
var dashboardHandler = Handler(
handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
return BlocProvider<DashboardBloc>(
create: (_) => DashboardBloc(accountRepository: accountRepository),
child: DashboardPage(),
);
},
);
请帮助我!
Bloc 不适用于您推送到堆栈中的所有新页面,甚至不适用于新的小部件。要将现有的 bloc 提供给新页面,您必须使用 bloc provider。
Navigator.push(context,
MaterialPageRoute(
builder: (context1) =>
BlocProvider.value(
value: BlocProvider.of<BlocName>(context),
child: DashboardPage())));
我是 flutter 的新手,我试图在获得用户身份验证后允许我的应用程序移动到 DashboardPage,但我收到此错误:无法在此 DashboardPage 小部件上方找到正确的提供程序
发生这种情况是因为您使用的 BuildContext
不包括提供商
任您选择。
这是我的代码 auth_page 在这两种情况下,代码和生物识别身份验证必须始终指向 DashboardPage() :
class AuthPage extends StatelessWidget {
static String routeName = '/fingerprint';
Future<void> localAuth(BuildContext context) async {
final localAuth = LocalAuthentication();
final didAuthenticate = await localAuth.authenticateWithBiometrics(
localizedReason: 'Please authenticate');
if (didAuthenticate) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => DashboardPage()),
);
}
}
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
centerTitle: true,
),
body: Padding(
padding: EdgeInsets.all(32),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
buildPinScreen(context),
SizedBox(height: 24),
SizedBox(height: 24),
],
),
),
),
);
Widget buildPinScreen(BuildContext context) => buildButton(
text: 'UnLock',
icon: Icons.lock_open,
onClicked: () async {
screenLock(context: context, correctString: '1234',
canCancel: true,
didUnlocked: (){
Navigator.push(
context,
MaterialPageRoute(builder: (context) => DashboardPage()),
);
},
customizedButtonTap: () async {
await localAuth(context);
},
didOpened: () async {
await localAuth(context);
},
);
}
);
这是我的代码 class route_configuration :
final router = FluroRouter();
class RouteConfiguration {
static Future<void> register() async {
// Register the routes
router.define("/", handler: rootHandler);
router.define(AssetFormScreen.routeName, handler: assetFormHandler);
router.define(AssetTransferScreen.routeName, handler: assetTransferHandler);
router.define(ShareAddressScreen.routeName, handler: shareAddressHandler);
router.define(DashboardPage.routeName, handler: dashboardHandler);
}
}
这是我的代码 class route_handlers :
var rootHandler = Handler(
type: HandlerType.route,
handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
return MultiBlocProvider(
providers: [
BlocProvider<MainBloc>(
create: (_) => MainBloc(accountRepository: accountRepository),
),
BlocProvider<NavigationBloc>(
create: (_) => NavigationBloc(tabs[0]),
),
],
child: MainScreen(),
);
},
);
var assetTransferHandler = Handler(
handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
final asset = context?.settings?.arguments;
if (asset is! AlgorandStandardAsset) return null;
return BlocProvider(
create: (_) =>
AssetTransferBloc(accountRepository: accountRepository)..start(asset),
child: AssetTransferScreen(),
);
},
);
var assetFormHandler = Handler(
handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
return BlocProvider<AssetFormBloc>(
create: (_) => AssetFormBloc(accountRepository: accountRepository),
child: AssetFormScreen(),
);
},
);
var shareAddressHandler = Handler(
handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
final address = params['address']?[0] ?? '';
return BlocProvider<AssetFormBloc>(
create: (_) => AssetFormBloc(accountRepository: accountRepository),
child: ShareAddressScreen(
address: address,
),
);
},
);
var dashboardHandler = Handler(
handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
return BlocProvider<DashboardBloc>(
create: (_) => DashboardBloc(accountRepository: accountRepository),
child: DashboardPage(),
);
},
);
请帮助我!
Bloc 不适用于您推送到堆栈中的所有新页面,甚至不适用于新的小部件。要将现有的 bloc 提供给新页面,您必须使用 bloc provider。
Navigator.push(context,
MaterialPageRoute(
builder: (context1) =>
BlocProvider.value(
value: BlocProvider.of<BlocName>(context),
child: DashboardPage())));