Riverpod 没有重建预期的小部件
Riverpod is not rebulding expected widget
我正在试用 riverpod。当我尝试 'watch'(就像我对 provider 所做的那样)时,小部件没有更新。如果我返回并返回到此页面,它只会重建并且我会看到更改。
final randomize = Provider((_) => RandomizeChangeNotifier());
...
...
Text(
ref.watch(randomize).randomNumber?.toString() ??
'Generate A Random Number',
style: TextStyle(fontSize: 16),
)
ChangeNotifier class:
class RandomizeChangeNotifier extends ChangeNotifier {
final random = Random();
int? _randomNumber;
get randomNumber => _randomNumber;
int min = 0;
int max = 0;
generateRandomNumber(){
_randomNumber = min + random.nextInt(max + 1 - min);
notifyListeners();
}
}
final randomize = Provider((_) => RandomizeChangeNotifier());
应该是 ChangeNotiferProvider
final randomize = ChangeNotifierProvider((_) => RandomizeChangeNotifier());
我正在试用 riverpod。当我尝试 'watch'(就像我对 provider 所做的那样)时,小部件没有更新。如果我返回并返回到此页面,它只会重建并且我会看到更改。
final randomize = Provider((_) => RandomizeChangeNotifier());
...
...
Text(
ref.watch(randomize).randomNumber?.toString() ??
'Generate A Random Number',
style: TextStyle(fontSize: 16),
)
ChangeNotifier class:
class RandomizeChangeNotifier extends ChangeNotifier {
final random = Random();
int? _randomNumber;
get randomNumber => _randomNumber;
int min = 0;
int max = 0;
generateRandomNumber(){
_randomNumber = min + random.nextInt(max + 1 - min);
notifyListeners();
}
}
final randomize = Provider((_) => RandomizeChangeNotifier());
应该是 ChangeNotiferProvider
final randomize = ChangeNotifierProvider((_) => RandomizeChangeNotifier());