很容易说出class RecipeProvider with ChangeNotifier {
bool isLoading = false;
void fetchAnyData(BuildContext context) {
//your data fetching logic
isLoading = true;
ApiManager.downloadRecipeApi().then((recipeList) {
this.recipes = recipeList;
isLoading = false;
notifyListeners();
print("===Success $recipeList");
}).catchError((onError) {
isLoading = false;
notifyListeners();
print("===onError $onError");
Toast.show(onError.errorMsg, context, duration: 2);
});
}
}
使用了什么class ProviderFetchWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final _provider = Provider.of<RecipeProvider>(context);
_provider.fetchAnyData(context);
return Scaffold(
body: provider == null || provider.isLoading
? Center(child: CircularProgressIndicator())
: Center(child: Text("Instead of text you can use your listview widget")),
);
}
,但是反过来又怎么样了:如果您有class
并想查看附件viewController
至。有没有办法做到这一点?我现在处于一个特殊的位置,在class
中进行了更改,但不知道如何测试更改,因为我不知道要在模拟器中输入哪个viewController
来查看结果。