**这是我的提供商**
MultiProvider(
child: MyApp(),
providers: [
ChangeNotifierProvider(create: (BuildContext context)=> Downloads(),),)]
***当我打印出_progress时,此类实现了notifylistner,所有这些都可以正常工作 但ui wiget不会重复输出***
class Downloads extends ChangeNotifier {
int _progress= 0;
int get progress => _progress;
void setProgress(int p) {
_progress = p;
notifyListeners();
}
}
我已删除进度条小部件,使其变得简单,而是显示输出值
class FileDownload extends StatelessWidget {
const FileDownload({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(body: progessUi());
}
}
class progessUi extends StatelessWidget {
const progessUi({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
final model = Provider.of<Downloads>(context);
return Container(child: Text(model.progress.toString()));
}
}
*这只是一个片段,其中调用了Download函数*
if (message['event'] == EV_PROGRESS) {
Downloads().setProgress(message['progress']);
}
if (message['event'] == EV_DONE) {
Downloads().setProgress(100);
}