dio throw #2352
bkparmar007
started this conversation in
General
dio throw
#2352
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
import 'package:flutter/material.dart';
import 'package:untitled/api_service/api_service.dart';
import 'package:untitled/model/user_model.dart';
class UserProvider extends ChangeNotifier {
final ApiService apiService = ApiService();
List post = [];
bool isLoading = false;
String error = "";
Future fetchpost() async {
isLoading = true;
notifyListeners();
try {
post = await apiService.fetchdata();
isLoading = false;
notifyListeners();
} catch (e) {
isLoading = true;
error = e.toString();
notifyListeners();
}
}
}
// Future<List> fetchdata() async {
// try {
// final response = await _dio.get(url);
// if (response.statusCode == 200) {
// List post =
// (response.data as List).map((e) => UserModel.fromJson(e)).toList();
// return post;
// } else {
// throw Exception('failed');
// }
// } catch (e) {
// throw e.toString();
// }
// }
Beta Was this translation helpful? Give feedback.
All reactions