fluent_networking

Last updated:

0 purchases

fluent_networking Image
fluent_networking Images
Add to Cart

Description:

fluent networking

fluent_networking #
Package that provides a simple way to make http requests
Getting Started #
Add dependencies #
fluent_networking: ^0.0.4
copied to clipboard
Create networking config #
class ApiConfig extends NetworkingConfig {
@override
String get baseUrl => "https://pokeapi.co/api/v2";
}
copied to clipboard
Build module #
void main() async {
await Fluent.build([
NetworkingModule(config: ApiConfig()),
]);

runApp(const MainApp());
}
copied to clipboard
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(),
);
},
),
),
);
}
}
copied to clipboard
Example #

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.