network_bound_resource 1.1.0 copy "network_bound_resource: ^1.1.0" to clipboard
network_bound_resource: ^1.1.0 copied to clipboard

A package to handle online and offline http requests. This package helps your app to save data offline and sync later when the device has an internet connection

example/network_bound_resource_example.dart

import 'dart:developer';

// ignore: depend_on_referenced_packages
import 'package:flutter/material.dart';
import 'package:network_bound_resource/src/domain/network_bound_resource.dart';

import 'data/remote_data_source.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({required this.title, super.key});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  late final RemoteDataSource remoteDataSource;

  @override
  void initState() {
    remoteDataSource = RemoteDataSource(NetworkBoundResource(
      'https://jsonplaceholder.typicode.com/',
    ));
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            ElevatedButton(
                onPressed: () async {
                  final posts = remoteDataSource.getPosts();
                  log(posts.toString());
                },
                child: const Text('Get posts'))
          ],
        ),
      ),
    );
  }
}
0
likes
140
points
49
downloads

Publisher

unverified uploader

Weekly Downloads

A package to handle online and offline http requests. This package helps your app to save data offline and sync later when the device has an internet connection

Repository (GitHub)

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

connectivity_plus, dio, flutter, path, path_provider, sembast

More

Packages that depend on network_bound_resource