fetcher 0.0.3 copy "fetcher: ^0.0.3" to clipboard
fetcher: ^0.0.3 copied to clipboard

outdated

Flutter package to Fetch and display asynchronous data easily

example/lib/main.dart

import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:fetcher/fetcher.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return DefaultFetcherConfig(
      config: FetcherConfig(
        showError: (context, error) => ScaffoldMessenger.of(context).showSnackBar(SnackBar(
          content: Text(error.toString()),
        )),
      ),
      child: MaterialApp(
        title: 'Fetcher Example',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: const MyHomePage(),
      ),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({Key? key}) : super(key: key);

  Future<String> fetchTask() async {
    final response = await http.get(Uri.parse('http://worldtimeapi.org/api/timezone/Europe/Paris'));
    await Future.delayed(const Duration(seconds: 2));
    return json.decode(response.body)['datetime'];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Fetcher Example'),
      ),
      body: FetchBuilder.basic<String>(
        task: fetchTask,
        builder: (context, data) {
          return Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Text(
                'Data is fetched :',
                style: Theme.of(context).textTheme.subtitle1,
                textAlign: TextAlign.center,
              ),
              Text(
                data,
                textAlign: TextAlign.center,
              ),
            ],
          );
        },
      ),
    );
  }
}
5
likes
0
points
2.1k
downloads

Publisher

verified publishericysun.fr

Weekly Downloads

Flutter package to Fetch and display asynchronous data easily

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, rxdart

More

Packages that depend on fetcher