0 purchases
dynamic base url
Dynamically change base url of your dio client or http client at runtime.
📚 Guide #
Initialize dynamic_base_url using BASEURL.init inside main() method.
void main() {
WidgetsFlutterBinding.ensureInitialized();
/// Initialize BASE URL
BASEURL.init(
debug: 'https://dummyjson.com',
prod: 'https://jsonplaceholder.typicode.com',
);
runApp(const MyApp());
}
copied to clipboard
Add BaseWrapper in MaterialApp.builder.
.....
@override
Widget build(BuildContext context) {
return MaterialApp(
builder: (context, child) {
/// Set up [BaseWrapper]
return BaseWrapper(
builder: (context) => child!,
onBaseUrlChanged: () {},
);
},
home: const BaseURLUseExample(),
);
}
.....
copied to clipboard
Use BASEURL.URL in dio or http.
Direct
_dio.get("${BASEURL.URL}/todos/1")
copied to clipboard
Dio
/// User [BASEURL.URL] as a base url
_dio.options.baseUrl = BASEURL.URL;
copied to clipboard
If you are using service locator get_it then change client base url from BaseWrapper callback.
.....
return BaseWrapper(
builder: (context) => child!,
onBaseUrlChanged: () {
/// Change [baseUrl] here
GetIt.instance<Dio>().options.baseUrl = BASEURL.URL;
},
);
.....
copied to clipboard
Open Base URL settings using floating bubble.
License #
MIT License
Copyright (c) 2023 Ashutosh Mulik
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.