Closed warcayac closed 11 months ago
Hi,
first of all I can assure you, this package is not for test purposes but used by thousands of Flutter devs in production. I don't understand why you wrap the GetIt functions in a class with only static functions. Why not just assign the GetIt.I to a global variable or just use GetIt.I whenever you want to access get_it?
If you only have one async init function, then it's totally ok to await that before starting the app. However using registerSingletonAsync and then use allReady
in you futurehandler ensures that your apps UI is already started while your async function might wait for some network response. (isReady
is only needed in very special settings)
I recommend watching my talk https://youtu.be/YJ52kSfSMyM?si=Mia_0usLJJ1B_t9M to see how allReady
and registerAsyncSingleton can make your life easier.
Sure you can just use normal Singletons but then you don't have the option to switch implementations at runtime like I do here:
if (Platform.isIOS || Platform.isAndroid) {
di.registerSingleton<LocalNotificationService>(
LocalNotificationServiceImpl());
} else {
di.registerSingleton<LocalNotificationService>(
LocalNotificationServiceDesktop());
}
Also you won't have scopes which can be very handy.
Btw. injectable
isn't from me and was developed without my involvement,
You might also have a look at my watch_it package wich is the state management extension for get_it
I advocate practicality in my apps, so instead of adding two import sentences (one for Get_It and one for my class) I prefer one import sentence through a static class called GIt which works as your global variable getIt but much better, IMHO.
I've watched your video and I've understood your package a little better, however I'd suggest you generate practical examples for every functionality your package offers, that would help more. As the saying goes "more action and fewer words".
Anyway, thanks for your time and happy X-mas and happy new year.
Actually if you put all your registrations in one file you only have to import that one in all other files Am 28. Dez. 2023, 00:12 +0100 schrieb William Arcaya C. @.***>:
I advocate practicality in my apps, so instead of adding two import sentences (one for Get_It and one for my class) I prefer one import sentence through a static class called GIt which works as your global variable getIt but much better, IMHO. I've watched your video and I've understood your package a little better, however I'd suggest you generate practical examples for every functionality your package offers, that would help more. As the saying goes "more action and fewer words". Anyway, thanks for your time and happy X-mas and happy new year. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
I usually use Singletons, but I've read recommendations about using Get_It instead so I'm trying to give it a try. However, I have found a somewhat brief documentation on how to correctly use (through practical examples) each of the features offered by this package (a common bad practice of many packages). The tutorials that I have found on the Web are basically the same as what is shown in the Get_It documentation on Github, that is, they do not provide better knowledge about the use of the other features not exemplified in the original documentation. Even searching GitHub there are very few cases where unexemplified cases (like registerSingletonAsync) are addressed.
Part I
Let's look at the following demo app:
my.env
openweather.dart
anyclass.dart
home_page.dart
main.dart
This app runs as expected, I can even remove the
allReady
variable and theFutureBuilder
widget, and the app still runs without problems.main.dart
home_page.dart
Part II
Now I gonna change/add some files to use them with Get_It package:
openweather.dart
di.dart
main.dart
home_page.dart
Observations
registerSingletonAsync
because it appears to be the best fit for this purpose, I'm not sure, I don't even know if I should usesignalsReady
parameter and how to use it for this example, I tried but I get errors,GetIt.I.getAsync<OpenWeather>()
because withget
method I get async errorsFutureBuilder
to use my singleton, there is no other optionAnyClass
class because using the singleton in it makes it unnecessarily(?) complex because of the asynchronous returnPart III
injectable
package even less attractive to useIf any assessment is wrong I would appreciate appropriate guidance.