flutter_network_plus 0.1.0
flutter_network_plus: ^0.1.0 copied to clipboard
An enterprise-grade, Dio-free networking foundation for Flutter: pluggable transport adapters, JWT auto-refresh with request queueing, smart retries, circuit breaker, TTL cache with stale-while-revali [...]
import 'package:flutter/material.dart';
import 'di.dart';
import 'screens/download_screen.dart';
import 'screens/inspector_screen.dart';
import 'screens/todos_screen.dart';
void main() {
runApp(ExampleApp(dependencies: AppDependencies()));
}
/// Root widget wiring the composition root into the widget tree.
class ExampleApp extends StatelessWidget {
const ExampleApp({required this.dependencies, super.key});
final AppDependencies dependencies;
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'flutter_network_plus',
theme: ThemeData(colorSchemeSeed: Colors.indigo, useMaterial3: true),
home: HomePage(dependencies: dependencies),
);
}
}
/// Bottom-navigation shell hosting the three demo screens.
class HomePage extends StatefulWidget {
const HomePage({required this.dependencies, super.key});
final AppDependencies dependencies;
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int _index = 0;
late String _environment = widget.dependencies.client.environment.name;
@override
Widget build(BuildContext context) {
final deps = widget.dependencies;
final pages = [
TodosScreen(api: deps.todoApi),
InspectorScreen(inspector: deps.inspector),
DownloadScreen(client: deps.client),
];
return Scaffold(
appBar: AppBar(
title: const Text('flutter_network_plus'),
actions: [
// Runtime environment switching.
PopupMenuButton<String>(
initialValue: _environment,
onSelected: (name) {
deps.client.switchEnvironment(name);
setState(() => _environment = name);
},
itemBuilder: (context) => deps.client.environments.all
.map((e) => PopupMenuItem(value: e.name, child: Text(e.name)))
.toList(),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Row(
children: [
Text(_environment),
const Icon(Icons.arrow_drop_down),
],
),
),
),
],
),
body: IndexedStack(index: _index, children: pages),
bottomNavigationBar: NavigationBar(
selectedIndex: _index,
onDestinationSelected: (i) => setState(() => _index = i),
destinations: const [
NavigationDestination(icon: Icon(Icons.checklist), label: 'Todos'),
NavigationDestination(icon: Icon(Icons.timeline), label: 'Inspector'),
NavigationDestination(icon: Icon(Icons.download), label: 'Download'),
],
),
);
}
}