Showing
4 changed files
with
49 additions
and
54 deletions
@@ -800,6 +800,24 @@ class Third extends StatelessWidget { | @@ -800,6 +800,24 @@ class Third extends StatelessWidget { | ||
800 | } | 800 | } |
801 | ``` | 801 | ``` |
802 | 802 | ||
803 | +### Change Theme | ||
804 | +Please do not use any higher level widget than GetMaterialApp in order to update it. This can trigger duplicate keys. A lot of people are used to the prehistoric approach of creating a "ThemeProvider" widget just to change the theme of your app, and this is definitely NOT necessary with Get. | ||
805 | +If you want to change the theme, just use: | ||
806 | + | ||
807 | +```dart | ||
808 | +Get.changeTheme (Theme.dark()); | ||
809 | +``` | ||
810 | + | ||
811 | +If you want to create something like a button that changes the theme with touch, you can combine two Get APIs for that, the api that checks if the dark theme is being used, and the theme change API, you can just put this within an onPressed: | ||
812 | + | ||
813 | +```dart | ||
814 | +Get.changeTheme (Get.isDarkMode? Theme.light(): Theme.dark()); | ||
815 | +``` | ||
816 | + | ||
817 | +When darkmode is activated, it will switch to the light theme, and when the light theme is activated, it will change to dark. | ||
818 | + | ||
819 | +You can create your custom theme and simply add it within Get.changeTheme without any cliche code for that. | ||
820 | + | ||
803 | ### Optional Global Settings | 821 | ### Optional Global Settings |
804 | You can create Global settings for Get. Just add Get.config to your code before pushing any route or do it directly in your GetMaterialApp | 822 | You can create Global settings for Get. Just add Get.config to your code before pushing any route or do it directly in your GetMaterialApp |
805 | 823 |
@@ -596,11 +596,11 @@ class Get { | @@ -596,11 +596,11 @@ class Get { | ||
596 | GetMaterialController get getController => _getController; | 596 | GetMaterialController get getController => _getController; |
597 | 597 | ||
598 | Get.changeTheme(ThemeData theme) { | 598 | Get.changeTheme(ThemeData theme) { |
599 | - _get._getController.setTheme(theme); | 599 | + Get()._getController.setTheme(theme); |
600 | } | 600 | } |
601 | 601 | ||
602 | Get.restartApp() { | 602 | Get.restartApp() { |
603 | - _get._getController.restartApp(); | 603 | + Get()._getController.restartApp(); |
604 | } | 604 | } |
605 | 605 | ||
606 | static GlobalKey<NavigatorState> addKey(GlobalKey<NavigatorState> newKey) { | 606 | static GlobalKey<NavigatorState> addKey(GlobalKey<NavigatorState> newKey) { |
@@ -619,8 +619,8 @@ class Get { | @@ -619,8 +619,8 @@ class Get { | ||
619 | Map<int, GlobalKey<NavigatorState>> _keys = {}; | 619 | Map<int, GlobalKey<NavigatorState>> _keys = {}; |
620 | 620 | ||
621 | static GlobalKey<NavigatorState> nestedKey(int key) { | 621 | static GlobalKey<NavigatorState> nestedKey(int key) { |
622 | - _get._keys.putIfAbsent(key, () => GlobalKey<NavigatorState>()); | ||
623 | - return _get._keys[key]; | 622 | + Get()._keys.putIfAbsent(key, () => GlobalKey<NavigatorState>()); |
623 | + return Get()._keys[key]; | ||
624 | } | 624 | } |
625 | 625 | ||
626 | GlobalKey<NavigatorState> global(int k) { | 626 | GlobalKey<NavigatorState> global(int k) { |
@@ -710,30 +710,6 @@ class Get { | @@ -710,30 +710,6 @@ class Get { | ||
710 | } | 710 | } |
711 | } | 711 | } |
712 | 712 | ||
713 | - static S findInstance<S>(_FcBuilderFunc<S> instance, {String name}) { | ||
714 | - if (Get()._singl.containsKey(_getKey(instance.call().runtimeType, name))) { | ||
715 | - String key = _getKey(instance.call().runtimeType, name); | ||
716 | - _FcBuilder builder = Get()._singl[key]; | ||
717 | - if (builder == null) { | ||
718 | - if (name == null) { | ||
719 | - throw "class ${S.toString()} is not register"; | ||
720 | - } else { | ||
721 | - throw "class ${S.toString()} with name '$name' is not register"; | ||
722 | - } | ||
723 | - } | ||
724 | - return Get()._singl[key].getSependency(); | ||
725 | - } else { | ||
726 | - if (!Get()._factory.containsKey(instance.call().runtimeType)) | ||
727 | - throw " $S not found. You need call Get.put<$S>($S()) before"; | ||
728 | - | ||
729 | - if (isLogEnable) print('[GET] $S instance was created at that time'); | ||
730 | - S _value = | ||
731 | - Get.put<S>(Get()._factory[instance.call().runtimeType].call() as S); | ||
732 | - Get()._factory.remove(instance.call().runtimeType); | ||
733 | - return _value; | ||
734 | - } | ||
735 | - } | ||
736 | - | ||
737 | /// Remove dependency of [S] on dependency abstraction. For concrete class use Get.delete | 713 | /// Remove dependency of [S] on dependency abstraction. For concrete class use Get.delete |
738 | static void remove<S>({String name}) { | 714 | static void remove<S>({String name}) { |
739 | String key = _getKey(S, name); | 715 | String key = _getKey(S, name); |
@@ -777,78 +753,78 @@ class Get { | @@ -777,78 +753,78 @@ class Get { | ||
777 | Get()._singl.containsKey(_getKey(S, name)); | 753 | Get()._singl.containsKey(_getKey(S, name)); |
778 | 754 | ||
779 | /// give access to Routing API from GetObserver | 755 | /// give access to Routing API from GetObserver |
780 | - static Routing get routing => _get._routing; | 756 | + static Routing get routing => Get()._routing; |
781 | 757 | ||
782 | - static RouteSettings get routeSettings => _get._settings; | 758 | + static RouteSettings get routeSettings => Get()._settings; |
783 | 759 | ||
784 | Routing _routing; | 760 | Routing _routing; |
785 | 761 | ||
786 | Map<String, String> _parameters = {}; | 762 | Map<String, String> _parameters = {}; |
787 | 763 | ||
788 | Get.setParameter(Map<String, String> param) { | 764 | Get.setParameter(Map<String, String> param) { |
789 | - _parameters = param; | 765 | + Get()._parameters = param; |
790 | } | 766 | } |
791 | 767 | ||
792 | Get.setRouting(Routing rt) { | 768 | Get.setRouting(Routing rt) { |
793 | - _routing = rt; | 769 | + Get()._routing = rt; |
794 | } | 770 | } |
795 | 771 | ||
796 | Get.setSettings(RouteSettings settings) { | 772 | Get.setSettings(RouteSettings settings) { |
797 | - _settings = settings; | 773 | + Get()._settings = settings; |
798 | } | 774 | } |
799 | 775 | ||
800 | /// give current arguments | 776 | /// give current arguments |
801 | - static Object get arguments => _get._routing.args; | 777 | + static Object get arguments => Get()._routing.args; |
802 | 778 | ||
803 | /// give current arguments | 779 | /// give current arguments |
804 | - static Map<String, String> get parameters => _get._parameters; | 780 | + static Map<String, String> get parameters => Get()._parameters; |
805 | 781 | ||
806 | /// interface to GetX | 782 | /// interface to GetX |
807 | RxInterface _obs; | 783 | RxInterface _obs; |
808 | 784 | ||
809 | - static RxInterface get obs => _get._obs; | 785 | + static RxInterface get obs => Get()._obs; |
810 | 786 | ||
811 | - static set obs(RxInterface observer) => _get._obs = observer; | 787 | + static set obs(RxInterface observer) => Get()._obs = observer; |
812 | 788 | ||
813 | /// give arguments from previous route | 789 | /// give arguments from previous route |
814 | - static get previousArguments => _get._routing.previousArgs; | 790 | + static get previousArguments => Get()._routing.previousArgs; |
815 | 791 | ||
816 | /// give name from current route | 792 | /// give name from current route |
817 | - static get currentRoute => _get._routing.current; | 793 | + static get currentRoute => Get()._routing.current; |
818 | 794 | ||
819 | /// give name from previous route | 795 | /// give name from previous route |
820 | - static get previousRoute => _get._routing.previous; | 796 | + static get previousRoute => Get()._routing.previous; |
821 | 797 | ||
822 | /// check if snackbar is open | 798 | /// check if snackbar is open |
823 | - static bool get isSnackbarOpen => _get._routing.isSnackbar; | 799 | + static bool get isSnackbarOpen => Get()._routing.isSnackbar; |
824 | 800 | ||
825 | /// check if dialog is open | 801 | /// check if dialog is open |
826 | - static bool get isDialogOpen => _get._routing.isDialog; | 802 | + static bool get isDialogOpen => Get()._routing.isDialog; |
827 | 803 | ||
828 | /// check if bottomsheet is open | 804 | /// check if bottomsheet is open |
829 | - static bool get isBottomSheetOpen => _get._routing.isBottomSheet; | 805 | + static bool get isBottomSheetOpen => Get()._routing.isBottomSheet; |
830 | 806 | ||
831 | /// check a raw current route | 807 | /// check a raw current route |
832 | - static Route<dynamic> get rawRoute => _get._routing.route; | 808 | + static Route<dynamic> get rawRoute => Get()._routing.route; |
833 | 809 | ||
834 | /// check if log is enable | 810 | /// check if log is enable |
835 | - static bool get isLogEnable => _get._enableLog; | 811 | + static bool get isLogEnable => Get()._enableLog; |
836 | 812 | ||
837 | /// default duration of transition animation | 813 | /// default duration of transition animation |
838 | /// default duration work only API 2.0 | 814 | /// default duration work only API 2.0 |
839 | static Duration get defaultDurationTransition => | 815 | static Duration get defaultDurationTransition => |
840 | - _get._defaultDurationTransition; | 816 | + Get()._defaultDurationTransition; |
841 | 817 | ||
842 | /// give global state of all GetState by default | 818 | /// give global state of all GetState by default |
843 | - static bool get defaultGlobalState => _get._defaultGlobalState; | 819 | + static bool get defaultGlobalState => Get()._defaultGlobalState; |
844 | 820 | ||
845 | /// check if popGesture is enable | 821 | /// check if popGesture is enable |
846 | - static bool get isPopGestureEnable => _get._defaultPopGesture; | 822 | + static bool get isPopGestureEnable => Get()._defaultPopGesture; |
847 | 823 | ||
848 | /// check if default opaque route is enable | 824 | /// check if default opaque route is enable |
849 | - static bool get isOpaqueRouteDefault => _get._defaultOpaqueRoute; | 825 | + static bool get isOpaqueRouteDefault => Get()._defaultOpaqueRoute; |
850 | 826 | ||
851 | - static Transition get defaultTransition => _get._defaultTransition; | 827 | + static Transition get defaultTransition => Get()._defaultTransition; |
852 | 828 | ||
853 | /// give access to currentContext | 829 | /// give access to currentContext |
854 | static BuildContext get context => key.currentContext; | 830 | static BuildContext get context => key.currentContext; |
@@ -374,9 +374,10 @@ class _GetBarState<K extends Object> extends State<GetBar> | @@ -374,9 +374,10 @@ class _GetBarState<K extends Object> extends State<GetBar> | ||
374 | : widget.backgroundColor, | 374 | : widget.backgroundColor, |
375 | child: SafeArea( | 375 | child: SafeArea( |
376 | minimum: widget.snackPosition == SnackPosition.BOTTOM | 376 | minimum: widget.snackPosition == SnackPosition.BOTTOM |
377 | - ? EdgeInsets.only( | ||
378 | - bottom: MediaQuery.of(context).viewInsets.bottom) | ||
379 | - : EdgeInsets.only(top: MediaQuery.of(context).viewInsets.top), | 377 | + ? EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom) |
378 | + : | ||
379 | + // EdgeInsets.only(top: MediaQuery.of(context).viewInsets.top), | ||
380 | + EdgeInsets.only(top: MediaQuery.of(context).padding.top), | ||
380 | bottom: widget.snackPosition == SnackPosition.BOTTOM, | 381 | bottom: widget.snackPosition == SnackPosition.BOTTOM, |
381 | top: widget.snackPosition == SnackPosition.TOP, | 382 | top: widget.snackPosition == SnackPosition.TOP, |
382 | left: false, | 383 | left: false, |
1 | name: get | 1 | name: get |
2 | description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get. | 2 | description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get. |
3 | -version: 2.5.2 | 3 | +version: 2.5.5 |
4 | homepage: https://github.com/jonataslaw/get | 4 | homepage: https://github.com/jonataslaw/get |
5 | 5 | ||
6 | environment: | 6 | environment: |
-
Please register or login to post a comment