juice_network 0.7.0 copy "juice_network: ^0.7.0" to clipboard
juice_network: ^0.7.0 copied to clipboard

Unified network BLoC for Flutter - request coalescing, caching, retry, and interceptors built on the Juice framework.

example/lib/main.dart

import 'package:juice/juice.dart';
import 'package:juice_network/juice_network.dart';
import 'package:juice_storage/juice_storage.dart';

import 'screens/home_screen.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // Register StorageBloc as permanent
  if (!BlocScope.isRegistered<StorageBloc>()) {
    BlocScope.register<StorageBloc>(
      () => StorageBloc(
        config: StorageConfig(
          prefsKeyPrefix: 'fetch_arcade_',
          hiveBoxesToOpen: [CacheManager.cacheBoxName],
        ),
      ),
      lifecycle: BlocLifecycle.permanent,
    );
  }

  // Initialize storage
  final storageBloc = BlocScope.get<StorageBloc>();
  await storageBloc.initialize();

  // Register FetchBloc as permanent
  if (!BlocScope.isRegistered<FetchBloc>()) {
    BlocScope.register<FetchBloc>(
      () => FetchBloc(storageBloc: storageBloc),
      lifecycle: BlocLifecycle.permanent,
    );
  }

  // Initialize FetchBloc with JSONPlaceholder config
  final fetchBloc = BlocScope.get<FetchBloc>();
  await fetchBloc.send(InitializeFetchEvent(
    config: FetchConfig(
      baseUrl: 'https://jsonplaceholder.typicode.com',
      connectTimeout: const Duration(seconds: 10),
      receiveTimeout: const Duration(seconds: 10),
      defaultTtl: const Duration(minutes: 5),
    ),
  ));

  runApp(const FetchArcadeApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Fetch Arcade',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(
          seedColor: Colors.deepPurple,
          brightness: Brightness.light,
        ),
        useMaterial3: true,
      ),
      darkTheme: ThemeData(
        colorScheme: ColorScheme.fromSeed(
          seedColor: Colors.deepPurple,
          brightness: Brightness.dark,
        ),
        useMaterial3: true,
      ),
      home: const HomeScreen(),
    );
  }
}
2
likes
160
points
159
downloads

Publisher

unverified uploader

Weekly Downloads

Unified network BLoC for Flutter - request coalescing, caching, retry, and interceptors built on the Juice framework.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#bloc #state-management #network #http #caching

Documentation

API reference

Funding

Consider supporting this project:

github.com

License

MIT (license)

Dependencies

crypto, dio, flutter, juice, juice_storage

More

Packages that depend on juice_network