我正在尝试使用 library Provider 的 multiprovider。但它不起作用,因为尽管材料之前的上部小部件是 MultiProvider,但它无法找到正确的提供者。
我已经尝试导入任何东西,但它仍然无法正常工作
class _LoginViewState extends State<LoginView> {
final TextEditingController _controller = TextEditingController();
@override
Widget build(BuildContext context) {
return BaseView<LoginModel>(
builder: (context, model, child) => Scaffold(
backgroundColor: backgroundColor,
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
StreamBuilder<Chat>(
stream: Provider.of<Socketio>(context).streamChat,
builder: (context, snapshot) {
return Text(snapshot.data?.toString() ?? 'Foo');
},
),
LoginHeader(
validationMessage: model.errorMessage,
controller: _controller),
model.state == ViewState.Busy
? CircularProgressIndicator()
那是我可以调用 Provider.of 的地方
void main() {
setupLocator();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
StreamProvider<User>(
initialData: User.initial(),
builder: (context) => locator<AuthenticationService>().userController,
),
StreamProvider<Chat>(
initialData: Chat.initial(),
builder: (context) => locator<Socketio>().chatController,
),
],
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(),
initialRoute: '/login',
onGenerateRoute: Router.generateRoute,
),
);
}
}```
this is where I provider socket io provider before Maetrialapp inside Multi Provider