提出问题
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class TestProviderWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [ChangeNotifierProvider(create: (_) => TestModel())],
child: Column(
children: [TestChildWidget1(), TestChildWidget2()],
));
}
}
class TestChildWidget1 extends StatelessWidget {
var provider;
@override
Widget build(BuildContext context) {
provider ??= Provider.of<TestModel>(context);
return Column(
children: [
Text("child1"),
FlatButton(
child: Text("num加1"),
onPressed: () {
provider.increase();
},
),
Text("${provider.num}"),
],
);
}
}
class TestChildWidget2 extends StatelessWidget {
var provider;
@override
Widget build(BuildC