fluent_networking 0.0.3 fluent_networking: ^0.0.3 copied to clipboard
Package that provides a simple way to make http requests
fluent_networking #
Package that provides a simple way to make http requests
Getting Started #
Add dependencies #
fluent_networking: ^0.0.3
Create networking config #
class ApiConfig extends NetworkingConfig {
@override
String get baseUrl => "https://pokeapi.co/api/v2";
}
Build module #
Fluent.build([
NetworkingModule(),
]);
Use it #
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
// Get networking api
final networkingApi = Fluent.get<NetworkingApi>();
// Make get request
final future = networkingApi.get<Map<String, dynamic>>("/pokemon");
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text("Fluent Networking Demo"),
),
body: FutureBuilder(
future: future,
builder: (context, snapshot) {
return snapshot.data?.when(
succeeded: (data) {
final results = data["results"];
return ListView.builder(
itemCount: results.length,
itemBuilder: (context, index) {
return ListTile(
leading: Text(results[index]["name"]),
title: Text(results[index]["url"]),
);
},
);
},
failed: (data) => const Text("Failed error"),
error: (error) => Text(error.message ?? ""),
) ??
const Center(
child: CircularProgressIndicator(),
);
},
),
),
);
}
}