smart_fetch 1.0.1 copy "smart_fetch: ^1.0.1" to clipboard
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(),
  // );
}
3
likes
0
points
481
downloads

Publisher

unverified uploader

Weekly Downloads

Beautiful full-screen error pages for server side errors and no internet connection state.

Repository (GitHub)
View/report issues

Topics

#flutter #error-handling #timeout #no-internet #server-error

License

unknown (license)

Dependencies

connectivity_plus, flutter, http, lottie

More

Packages that depend on smart_fetch