class MeetingListModel with ChangeNotifier {
int _count = 0;
int get count => _count;
void add() {
_count++;
notifyListeners();
}
}
class MeetingList extends StatefulWidget {
@override
_MeetingListState createState() => _MeetingListState();
}
class _MeetingListState extends State<MeetingList> {
int type = 0;
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(
create: (_) => MeetingListModel(),
)
],
child: Scaffold(
body: Center(
child: Column(children: [
GestureDetector(
onTap: () {
context.watch<MeetingListModel>().add();
},
child: Text("会议列表")),
Text(context.watch<MeetingListModel>().count.toString()),
]),
),
));
}
}
这样写为什么会报错,按照推荐的写法
Widget build(BuildContext context) {
return Provider<Example>(
create: (_) => Example(),
builder: (context) {
return Text(context.watch<Example>()),
}),}
也同样报错,求解啊
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…