您好,我正在研究有关供应商的信息。
我只是在学习时移动了示例代码,但是发生以下错误。
库是否已更改或发生错误?
class BankAccount with ChangeNotifier {
int _balance = 0;
int getBalance() => _balance;
void increment(int value) {
_balance += value;
notifyListeners(); //must be inserted
}
void decrement(int value) {
_balance -= value;
notifyListeners(); //must be inserted
}
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider<BankAccount>(builder: (_) => BankAccount(),),//This is a problem
Provider<String>.value(value: "Park")
],
child: MaterialApp(
title: "Provider Test",
home: HomePage(),
),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
BankAccount bankAccount = Provider.of<BankAccount>(context);
String name = Provider.of<String>(context);
}
}