Skip to content

Commit

Permalink
improve support for custom initializers
Browse files Browse the repository at this point in the history
fix src import issue
  • Loading branch information
Milad Alakarie committed Feb 24, 2020
1 parent 31c5ea0 commit e97916f
Show file tree
Hide file tree
Showing 81 changed files with 1,469 additions and 604 deletions.
36 changes: 6 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void $initGetIt({String environment}) {
}
```

you could also create your own environment annotations by assigning the const constructor Enviromnent("") to a global const var.
you could also create your own environment annotations by assigning the const constructor Environment("") to a global const var.

```dart
const dev = const Environment('dev');
Expand Down Expand Up @@ -245,24 +245,15 @@ Generated code for the Above example
```dart
void $initGetIt(GetIt getIt, {String environment}) {
// ..other deps
//Register dev Dependencies --------
if (environment == 'dev') {
_registerDevDependencies(g);
g.registerFactory<Service>(() => FakeServiceImpl());
}
//Register prod Dependencies --------
if (environment == 'prod') {
_registerProdDependencies(g);
g.registerFactory<Service>(() => RealServiceImpl());
}
}
void _registerDevDependencies(GetIt g) {
g.registerFactory<Service>(() => FakeServiceImpl());
// ..other dev deps
}
void _registerProdDependencies(GetIt g) {
g.registerFactory<Service>(() => RealServiceImpl());
// ..other prod deps
}
```

## Using named factories and static create functions
Expand Down Expand Up @@ -339,21 +330,6 @@ abstract class RegisterModule {
}
```

generated code

```dart
Future<void> $initGetIt(GetIt g, {String environment}) async {
g.lazySingleton<Dio>(() => Dio(BaseOptions(baseUrl: "baseUrl")));
final sharedPreferences = await SharedPreferences.getInstance();
g.registerFactory<SharedPreferences>(() => sharedPreferences);
}
```

#### The limitation when providing custom initializers.

- You can only use arrow functions (Expressions) => "at least for now"
- Dependencies used in the custom initializers can not be imported automatically, meaning if you use any dependencies in your custom initializer make sure they're registered individually.

if you're facing even a weirder scenario you can always register them manually in the configure function.

## Auto registering $Experimental$
Expand Down Expand Up @@ -386,7 +362,7 @@ targets:
---
Make sure you always **Save** your files before running the generator, if that doesn't work you can always try to clean and rebuild.
Make sure you always **Save** your files before running the generator, if that does not work you can always try to clean and rebuild.
```terminal
flutter packages pub run build_runner clean
Expand Down
14 changes: 7 additions & 7 deletions example/.flutter-plugins
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# This is a generated file; do not edit or check into version control.
firebase_auth=/Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth-0.15.4/
firebase_auth_web=/Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_web-0.1.2/
firebase_core=/Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core-0.4.4/
firebase_core_web=/Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_web-0.1.1+2/
shared_preferences=/Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.6+1/
shared_preferences_macos=/Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+4/
shared_preferences_web=/Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+3/
firebase_auth=/Users/milad/.pub-cache/hosted/pub.dartlang.org/firebase_auth-0.15.4/
firebase_auth_web=/Users/milad/.pub-cache/hosted/pub.dartlang.org/firebase_auth_web-0.1.2/
firebase_core=/Users/milad/.pub-cache/hosted/pub.dartlang.org/firebase_core-0.4.4/
firebase_core_web=/Users/milad/.pub-cache/hosted/pub.dartlang.org/firebase_core_web-0.1.1+2/
shared_preferences=/Users/milad/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.6+1/
shared_preferences_macos=/Users/milad/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+4/
shared_preferences_web=/Users/milad/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+3/
168 changes: 84 additions & 84 deletions example/.packages

Large diffs are not rendered by default.

Binary file modified example/android/.gradle/4.10.2/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified example/android/.gradle/4.10.2/fileHashes/fileHashes.lock
Binary file not shown.
5 changes: 4 additions & 1 deletion example/android/local.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
sdk.dir=/Users/milad/Library/Android/sdk
flutter.sdk=/Users/milad/dev/sdk/flutter
flutter.sdk=/Users/milad/dev-tools/flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
192 changes: 143 additions & 49 deletions example/build/flutter_assets/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -4650,6 +4650,30 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------
dio

MIT License

Copyright (c) 2018 wendux

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:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--------------------------------------------------------------------------------
double-conversion
icu

Expand Down Expand Up @@ -4863,6 +4887,96 @@ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
firebase

Copyright (c) 2016, Google.

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:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--------------------------------------------------------------------------------
firebase_auth
firebase_auth_platform_interface
firebase_auth_web
firebase_core
firebase_core_platform_interface
shared_preferences
shared_preferences_platform_interface

// Copyright 2017 The Chromium Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------
firebase_core_web
shared_preferences_web

// Copyright 2019 The Chromium Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

--------------------------------------------------------------------------------
freetype2

Expand Down Expand Up @@ -9225,31 +9339,6 @@ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
--------------------------------------------------------------------------------
kiwi

MIT License

Copyright (c) 2018 Romain Rastel

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:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

--------------------------------------------------------------------------------
libXNVCtrl

Expand Down Expand Up @@ -11322,30 +11411,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

--------------------------------------------------------------------------------
provider

MIT License

Copyright (c) 2018 Remi Rousselet

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:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--------------------------------------------------------------------------------
quiver

Expand Down Expand Up @@ -12134,6 +12199,35 @@ Exhibit B - "Incompatible With Secondary Licenses" Notice
This Source Code Form is "Incompatible With Secondary Licenses", as
defined by the Mozilla Public License, v. 2.0.
--------------------------------------------------------------------------------
shared_preferences_macos

Copyright 2017, the Flutter project authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------
skcms

Copyright (c) 2018 Google Inc. All rights reserved.
Expand Down
Binary file modified example/build/flutter_assets/kernel_blob.bin
Binary file not shown.
Binary file modified example/build/ios/Debug-iphonesimulator/Runner.app/Assets.car
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</data>
<key>flutter_assets/LICENSE</key>
<data>
LGNJlLsq9qfnpVGKcfoel1fYRLg=
ziuTfnuGD4cjabGq9nRfPlh+CqU=
</data>
<key>flutter_assets/fonts/MaterialIcons-Regular.ttf</key>
<data>
Expand All @@ -30,7 +30,7 @@
</data>
<key>flutter_assets/kernel_blob.bin</key>
<data>
jUpx0FIhohUwfy7V35T3OPt3/m4=
UErdRGekrB+cPhxmBNadJR9vEjQ=
</data>
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
<data>
Expand Down Expand Up @@ -69,11 +69,11 @@
<dict>
<key>hash</key>
<data>
LGNJlLsq9qfnpVGKcfoel1fYRLg=
ziuTfnuGD4cjabGq9nRfPlh+CqU=
</data>
<key>hash2</key>
<data>
thIlCzldkdE4Q9B9e4D71TaK4NIJ/iBjNayYRDdfw4k=
GZxaN5oU6hwFgMtRKrC7bcU1LwoI4kOgS2ZnBYPfWqk=
</data>
</dict>
<key>flutter_assets/fonts/MaterialIcons-Regular.ttf</key>
Expand Down Expand Up @@ -102,11 +102,11 @@
<dict>
<key>hash</key>
<data>
jUpx0FIhohUwfy7V35T3OPt3/m4=
UErdRGekrB+cPhxmBNadJR9vEjQ=
</data>
<key>hash2</key>
<data>
LnelO5YRrQfXmCIxk+TTY1ASz9buz96RcDt4UZ1Lcic=
1QbovKwl3Q9ZbobXt9n9QE+DnVyLh1Ki/I3y48YPZ1U=
</data>
</dict>
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
Expand Down
Loading

0 comments on commit e97916f

Please sign in to comment.