smart_fetch 1.0.1
smart_fetch: ^1.0.1 copied to clipboard
Beautiful full-screen error pages for server side errors and no internet connection state.
example/smart_fetch_example.dart
import 'package:smart_fetch/smart_fetch.dart';
import 'package:http/http.dart' as http;
void main() async {
// Example 1: Using SmartFetch.call() for API requests
final result = await SmartFetch.call(
() => http.get(Uri.parse('https://api.example.com/data')),
timeout: const Duration(seconds: 10),
);
if (result.isSuccess) {
print('Success: ${result.response?.body}');
} else if (result.isNoInternet) {
print('No internet connection');
} else if (result.isTimeout) {
print('Request timed out');
} else {
print('Server error occurred');
}
// Example 2: Using SmartFetch.builder() in Flutter widgets
// This will automatically show appropriate error screens
// SmartFetch.builder(
// future: () => http.get(Uri.parse('https://api.example.com/data')),
// onSuccess: (context, response) {
// return Text('Data: ${response.body}');
// },
// loadingWidget: CircularProgressIndicator(),
// );
}