return 类型不是闭包上下文所要求的小部件
The return type isn't a widget as required by the closures context
我尝试完成教程,但出现此错误(查看图片)。
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:provider_architecture/core/viewmodels/login_model.dart';
import 'package:provider_architecture/locator.dart';
class LoginView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider<LoginModel>(
builder: (context) => locator<LoginModel>(), // the error is here
child: Consumer<LoginModel>(
builder: (context, model, child) => Scaffold(),
),
);
}
}
变化:
builder: (context) => locator<LoginModel>()
至:
create: (context) => locator<LoginModel>()
我尝试完成教程,但出现此错误(查看图片)。
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:provider_architecture/core/viewmodels/login_model.dart';
import 'package:provider_architecture/locator.dart';
class LoginView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider<LoginModel>(
builder: (context) => locator<LoginModel>(), // the error is here
child: Consumer<LoginModel>(
builder: (context, model, child) => Scaffold(),
),
);
}
}
变化:
builder: (context) => locator<LoginModel>()
至:
create: (context) => locator<LoginModel>()