Showing
1 changed file
with
0 additions
and
866 deletions
lib/src/get_main_backup.dart
deleted
100644 → 0
| 1 | -import 'package:flutter/material.dart'; | ||
| 2 | -import 'package:flutter/scheduler.dart'; | ||
| 3 | -import 'bottomsheet/bottomsheet.dart'; | ||
| 4 | -import 'platform/platform.dart'; | ||
| 5 | -import 'root/root_controller.dart'; | ||
| 6 | -import 'routes/default_route.dart'; | ||
| 7 | -import 'routes/observers/route_observer.dart'; | ||
| 8 | -import 'routes/transitions_type.dart'; | ||
| 9 | -import 'rx/rx_interface.dart'; | ||
| 10 | -import 'snackbar/snack.dart'; | ||
| 11 | - | ||
| 12 | -class Get { | ||
| 13 | - static Get _get; | ||
| 14 | - static GlobalKey<NavigatorState> _key; | ||
| 15 | - | ||
| 16 | - static GlobalKey<NavigatorState> addKey(GlobalKey<NavigatorState> newKey) { | ||
| 17 | - _key = newKey; | ||
| 18 | - return _key; | ||
| 19 | - } | ||
| 20 | - | ||
| 21 | - static GlobalKey<NavigatorState> get key { | ||
| 22 | - if (_key == null) { | ||
| 23 | - _key = GlobalKey<NavigatorState>(); | ||
| 24 | - } | ||
| 25 | - return _key; | ||
| 26 | - } | ||
| 27 | - | ||
| 28 | - ///Use Get.to instead of Navigator.push, Get.off instead of Navigator.pushReplacement, | ||
| 29 | - ///Get.offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named" | ||
| 30 | - ///after them. Example: Get.toNamed, Get.offNamed, and Get.AllNamed. | ||
| 31 | - ///To return to the previous screen, use Get.back(). | ||
| 32 | - ///No need to pass any context to Get, just put the name of the route inside | ||
| 33 | - ///the parentheses and the magic will occur. | ||
| 34 | - factory Get() { | ||
| 35 | - if (_get == null) _get = Get._(); | ||
| 36 | - return _get; | ||
| 37 | - } | ||
| 38 | - | ||
| 39 | - ///Use Get.to instead of Navigator.push, Get.off instead of Navigator.pushReplacement, | ||
| 40 | - ///Get.offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named" | ||
| 41 | - ///after them. Example: Get.toNamed, Get.offNamed, and Get.AllNamed. | ||
| 42 | - ///To return to the previous screen, use Get.back(). | ||
| 43 | - ///No need to pass any context to Get, just put the name of the route inside | ||
| 44 | - ///the parentheses and the magic will occur. | ||
| 45 | - Get._(); | ||
| 46 | - | ||
| 47 | - static bool _enableLog = true; | ||
| 48 | - static bool _defaultPopGesture = GetPlatform.isIOS; | ||
| 49 | - static bool _defaultOpaqueRoute = true; | ||
| 50 | - static Transition _defaultTransition = | ||
| 51 | - (GetPlatform.isIOS ? Transition.cupertino : Transition.fade); | ||
| 52 | - static Duration _defaultDurationTransition = Duration(milliseconds: 400); | ||
| 53 | - static bool _defaultGlobalState = true; | ||
| 54 | - static RouteSettings _settings; | ||
| 55 | - | ||
| 56 | - /// It replaces Navigator.push, but needs no context, and it doesn't have the Navigator.push | ||
| 57 | - /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior | ||
| 58 | - /// of rebuilding every app after a route, use opaque = true as the parameter. | ||
| 59 | - static Future<T> to<T>(Widget page, | ||
| 60 | - {bool opaque, | ||
| 61 | - Transition transition, | ||
| 62 | - Duration duration, | ||
| 63 | - int id, | ||
| 64 | - bool fullscreenDialog = false, | ||
| 65 | - Object arguments, | ||
| 66 | - bool popGesture}) { | ||
| 67 | - return global(id).currentState.push(GetRouteBase( | ||
| 68 | - opaque: opaque ?? true, | ||
| 69 | - page: page, | ||
| 70 | - settings: RouteSettings( | ||
| 71 | - name: '/' + page.toString().toLowerCase(), arguments: arguments), | ||
| 72 | - popGesture: popGesture ?? _defaultPopGesture, | ||
| 73 | - transition: transition ?? _defaultTransition, | ||
| 74 | - fullscreenDialog: fullscreenDialog, | ||
| 75 | - transitionDuration: duration ?? _defaultDurationTransition)); | ||
| 76 | - } | ||
| 77 | - | ||
| 78 | - /// It replaces Navigator.pushNamed, but needs no context, and it doesn't have the Navigator.pushNamed | ||
| 79 | - /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior | ||
| 80 | - /// of rebuilding every app after a route, use opaque = true as the parameter. | ||
| 81 | - static Future<T> toNamed<T>(String page, {arguments, int id}) { | ||
| 82 | - // if (key.currentState.mounted) // add this if appear problems on future with route navigate | ||
| 83 | - // when widget don't mounted | ||
| 84 | - return global(id).currentState.pushNamed(page, arguments: arguments); | ||
| 85 | - } | ||
| 86 | - | ||
| 87 | - /// It replaces Navigator.pushReplacementNamed, but needs no context. | ||
| 88 | - static Future<T> offNamed<T>(String page, {arguments, int id}) { | ||
| 89 | - // if (key.currentState.mounted) // add this if appear problems on future with route navigate | ||
| 90 | - // when widget don't mounted | ||
| 91 | - return global(id) | ||
| 92 | - .currentState | ||
| 93 | - .pushReplacementNamed(page, arguments: arguments); | ||
| 94 | - } | ||
| 95 | - | ||
| 96 | - /// It replaces Navigator.popUntil, but needs no context. | ||
| 97 | - static void until(predicate, {int id}) { | ||
| 98 | - // if (key.currentState.mounted) // add this if appear problems on future with route navigate | ||
| 99 | - // when widget don't mounted | ||
| 100 | - return global(id).currentState.popUntil(predicate); | ||
| 101 | - } | ||
| 102 | - | ||
| 103 | - /// It replaces Navigator.pushAndRemoveUntil, but needs no context. | ||
| 104 | - static Future<T> offUntil<T>(page, predicate, {int id}) { | ||
| 105 | - // if (key.currentState.mounted) // add this if appear problems on future with route navigate | ||
| 106 | - // when widget don't mounted | ||
| 107 | - return global(id).currentState.pushAndRemoveUntil(page, predicate); | ||
| 108 | - } | ||
| 109 | - | ||
| 110 | - /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context. | ||
| 111 | - static Future<T> offNamedUntil<T>(page, predicate, {int id}) { | ||
| 112 | - return global(id).currentState.pushNamedAndRemoveUntil(page, predicate); | ||
| 113 | - } | ||
| 114 | - | ||
| 115 | - /// It replaces Navigator.popAndPushNamed, but needs no context. | ||
| 116 | - static Future<T> offAndToNamed<T>(String page, {arguments, int id, result}) { | ||
| 117 | - return global(id) | ||
| 118 | - .currentState | ||
| 119 | - .popAndPushNamed(page, arguments: arguments, result: result); | ||
| 120 | - } | ||
| 121 | - | ||
| 122 | - /// It replaces Navigator.removeRoute, but needs no context. | ||
| 123 | - static void removeRoute(route, {int id}) { | ||
| 124 | - return global(id).currentState.removeRoute(route); | ||
| 125 | - } | ||
| 126 | - | ||
| 127 | - /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context. | ||
| 128 | - static Future<T> offAllNamed<T>(String newRouteName, | ||
| 129 | - {RoutePredicate predicate, arguments, int id}) { | ||
| 130 | - var route = (Route<dynamic> rota) => false; | ||
| 131 | - | ||
| 132 | - return global(id).currentState.pushNamedAndRemoveUntil( | ||
| 133 | - newRouteName, predicate ?? route, | ||
| 134 | - arguments: arguments); | ||
| 135 | - } | ||
| 136 | - | ||
| 137 | - static bool get isOverlaysOpen => | ||
| 138 | - (isSnackbarOpen || isDialogOpen || isBottomSheetOpen); | ||
| 139 | - | ||
| 140 | - static bool get isOverlaysClosed => | ||
| 141 | - (!Get.isSnackbarOpen && !Get.isDialogOpen && !Get.isBottomSheetOpen); | ||
| 142 | - | ||
| 143 | - /// It replaces Navigator.pop, but needs no context. | ||
| 144 | - static void back({dynamic result, bool closeOverlays = false, int id}) { | ||
| 145 | - if (closeOverlays && isOverlaysOpen) { | ||
| 146 | - navigator.popUntil((route) { | ||
| 147 | - return (isOverlaysClosed); | ||
| 148 | - }); | ||
| 149 | - } | ||
| 150 | - global(id).currentState.pop(result); | ||
| 151 | - } | ||
| 152 | - | ||
| 153 | - // /// Experimental API to back from overlay | ||
| 154 | - // static void backE({dynamic result}) { | ||
| 155 | - // Navigator.pop(overlayContext); | ||
| 156 | - // } | ||
| 157 | - | ||
| 158 | - /// It will close as many screens as you define. Times must be> 0; | ||
| 159 | - static void close(int times, [int id]) { | ||
| 160 | - if ((times == null) || (times < 1)) { | ||
| 161 | - times = 1; | ||
| 162 | - } | ||
| 163 | - int count = 0; | ||
| 164 | - void back = global(id).currentState.popUntil((route) { | ||
| 165 | - return count++ == times; | ||
| 166 | - }); | ||
| 167 | - return back; | ||
| 168 | - } | ||
| 169 | - | ||
| 170 | - /// It replaces Navigator.pushReplacement, but needs no context, and it doesn't have the Navigator.pushReplacement | ||
| 171 | - /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior | ||
| 172 | - /// of rebuilding every app after a route, use opaque = true as the parameter. | ||
| 173 | - static Future<T> off<T>(Widget page, | ||
| 174 | - {bool opaque = false, | ||
| 175 | - Transition transition, | ||
| 176 | - bool popGesture, | ||
| 177 | - int id, | ||
| 178 | - Object arguments, | ||
| 179 | - bool fullscreenDialog = false, | ||
| 180 | - Duration duration}) { | ||
| 181 | - return global(id).currentState.pushReplacement(GetRouteBase( | ||
| 182 | - opaque: opaque ?? true, | ||
| 183 | - page: page, | ||
| 184 | - settings: RouteSettings( | ||
| 185 | - name: '/' + page.toString().toLowerCase(), arguments: arguments), | ||
| 186 | - fullscreenDialog: fullscreenDialog, | ||
| 187 | - popGesture: popGesture ?? _defaultPopGesture, | ||
| 188 | - transition: transition ?? _defaultTransition, | ||
| 189 | - transitionDuration: duration ?? _defaultDurationTransition)); | ||
| 190 | - } | ||
| 191 | - | ||
| 192 | - /// It replaces Navigator.pushAndRemoveUntil, but needs no context | ||
| 193 | - static Future<T> offAll<T>(Widget page, | ||
| 194 | - {RoutePredicate predicate, | ||
| 195 | - bool opaque = false, | ||
| 196 | - bool popGesture, | ||
| 197 | - int id, | ||
| 198 | - Object arguments, | ||
| 199 | - bool fullscreenDialog = false, | ||
| 200 | - Transition transition}) { | ||
| 201 | - var route = (Route<dynamic> rota) => false; | ||
| 202 | - | ||
| 203 | - return global(id).currentState.pushAndRemoveUntil( | ||
| 204 | - GetRouteBase( | ||
| 205 | - opaque: opaque ?? true, | ||
| 206 | - popGesture: popGesture ?? _defaultPopGesture, | ||
| 207 | - page: page, | ||
| 208 | - settings: RouteSettings( | ||
| 209 | - name: '/' + page.toString().toLowerCase(), arguments: arguments), | ||
| 210 | - fullscreenDialog: fullscreenDialog, | ||
| 211 | - transition: transition ?? _defaultTransition, | ||
| 212 | - ), | ||
| 213 | - predicate ?? route); | ||
| 214 | - } | ||
| 215 | - | ||
| 216 | - /// Show a dialog | ||
| 217 | - static Future<T> dialog<T>( | ||
| 218 | - Widget child, { | ||
| 219 | - bool barrierDismissible = true, | ||
| 220 | - bool useRootNavigator = true, | ||
| 221 | - // RouteSettings routeSettings | ||
| 222 | - }) { | ||
| 223 | - return showDialog( | ||
| 224 | - barrierDismissible: barrierDismissible, | ||
| 225 | - useRootNavigator: useRootNavigator, | ||
| 226 | - routeSettings: RouteSettings(name: 'dialog'), | ||
| 227 | - context: overlayContext, | ||
| 228 | - builder: (_) { | ||
| 229 | - return child; | ||
| 230 | - }, | ||
| 231 | - ); | ||
| 232 | - } | ||
| 233 | - | ||
| 234 | - /// Api from showGeneralDialog with no context | ||
| 235 | - static Future<T> generalDialog<T>({ | ||
| 236 | - @required RoutePageBuilder pageBuilder, | ||
| 237 | - bool barrierDismissible, | ||
| 238 | - String barrierLabel, | ||
| 239 | - Color barrierColor, | ||
| 240 | - Duration transitionDuration, | ||
| 241 | - RouteTransitionsBuilder transitionBuilder, | ||
| 242 | - bool useRootNavigator = true, | ||
| 243 | - RouteSettings routeSettings, | ||
| 244 | - // RouteSettings routeSettings | ||
| 245 | - }) { | ||
| 246 | - return showGeneralDialog( | ||
| 247 | - pageBuilder: pageBuilder, | ||
| 248 | - barrierDismissible: barrierDismissible, | ||
| 249 | - barrierLabel: barrierLabel, | ||
| 250 | - barrierColor: barrierColor, | ||
| 251 | - transitionDuration: transitionDuration, | ||
| 252 | - transitionBuilder: transitionBuilder, | ||
| 253 | - useRootNavigator: useRootNavigator, | ||
| 254 | - routeSettings: RouteSettings(name: 'dialog'), | ||
| 255 | - context: overlayContext, | ||
| 256 | - ); | ||
| 257 | - } | ||
| 258 | - | ||
| 259 | - static Future<T> defaultDialog<T>({ | ||
| 260 | - String title = "Alert", | ||
| 261 | - Widget content, | ||
| 262 | - VoidCallback onConfirm, | ||
| 263 | - VoidCallback onCancel, | ||
| 264 | - VoidCallback onCustom, | ||
| 265 | - String textConfirm, | ||
| 266 | - String textCancel, | ||
| 267 | - String textCustom, | ||
| 268 | - Widget confirm, | ||
| 269 | - Widget cancel, | ||
| 270 | - Widget custom, | ||
| 271 | - Color backgroundColor, | ||
| 272 | - Color buttonColor, | ||
| 273 | - String middleText = "Dialog made in 3 lines of code", | ||
| 274 | - double radius = 20.0, | ||
| 275 | - List<Widget> actions, | ||
| 276 | - }) { | ||
| 277 | - bool leanCancel = onCancel != null || textCancel != null; | ||
| 278 | - bool leanConfirm = onConfirm != null || textConfirm != null; | ||
| 279 | - actions ??= []; | ||
| 280 | - | ||
| 281 | - if (cancel != null) { | ||
| 282 | - actions.add(cancel); | ||
| 283 | - } else { | ||
| 284 | - if (leanCancel) { | ||
| 285 | - actions.add(FlatButton( | ||
| 286 | - materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, | ||
| 287 | - onPressed: () { | ||
| 288 | - onCancel?.call(); | ||
| 289 | - Get.back(); | ||
| 290 | - }, | ||
| 291 | - padding: EdgeInsets.symmetric(horizontal: 10, vertical: 8), | ||
| 292 | - child: Text(textCancel ?? "Cancel"), | ||
| 293 | - shape: RoundedRectangleBorder( | ||
| 294 | - side: BorderSide( | ||
| 295 | - color: buttonColor ?? Get.theme.accentColor, | ||
| 296 | - width: 2, | ||
| 297 | - style: BorderStyle.solid), | ||
| 298 | - borderRadius: BorderRadius.circular(100)), | ||
| 299 | - )); | ||
| 300 | - } | ||
| 301 | - } | ||
| 302 | - if (confirm != null) { | ||
| 303 | - actions.add(confirm); | ||
| 304 | - } else { | ||
| 305 | - if (leanConfirm) { | ||
| 306 | - actions.add(FlatButton( | ||
| 307 | - materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, | ||
| 308 | - color: buttonColor ?? Get.theme.accentColor, | ||
| 309 | - shape: RoundedRectangleBorder( | ||
| 310 | - borderRadius: BorderRadius.circular(100)), | ||
| 311 | - child: Text(textConfirm ?? "Ok"), | ||
| 312 | - onPressed: () { | ||
| 313 | - onConfirm?.call(); | ||
| 314 | - })); | ||
| 315 | - } | ||
| 316 | - } | ||
| 317 | - return Get.dialog(AlertDialog( | ||
| 318 | - titlePadding: EdgeInsets.all(8), | ||
| 319 | - contentPadding: EdgeInsets.all(8), | ||
| 320 | - backgroundColor: backgroundColor ?? Get.theme.dialogBackgroundColor, | ||
| 321 | - shape: RoundedRectangleBorder( | ||
| 322 | - borderRadius: BorderRadius.all(Radius.circular(radius))), | ||
| 323 | - title: Text(title, textAlign: TextAlign.center), | ||
| 324 | - content: Column( | ||
| 325 | - crossAxisAlignment: CrossAxisAlignment.center, | ||
| 326 | - mainAxisSize: MainAxisSize.min, | ||
| 327 | - children: [ | ||
| 328 | - content ?? Text(middleText ?? "", textAlign: TextAlign.center), | ||
| 329 | - SizedBox(height: 16), | ||
| 330 | - ButtonTheme( | ||
| 331 | - minWidth: 78.0, | ||
| 332 | - height: 34.0, | ||
| 333 | - child: Wrap( | ||
| 334 | - alignment: WrapAlignment.center, | ||
| 335 | - spacing: 8, | ||
| 336 | - runSpacing: 8, | ||
| 337 | - children: actions, | ||
| 338 | - ), | ||
| 339 | - ) | ||
| 340 | - ], | ||
| 341 | - ), | ||
| 342 | - // actions: actions, // ?? <Widget>[cancelButton, confirmButton], | ||
| 343 | - buttonPadding: EdgeInsets.zero, | ||
| 344 | - )); | ||
| 345 | - } | ||
| 346 | - | ||
| 347 | - static Future<T> bottomSheet<T>( | ||
| 348 | - Widget bottomsheet, { | ||
| 349 | - Color backgroundColor, | ||
| 350 | - double elevation, | ||
| 351 | - ShapeBorder shape, | ||
| 352 | - Clip clipBehavior, | ||
| 353 | - Color barrierColor, | ||
| 354 | - bool ignoreSafeArea, | ||
| 355 | - bool isScrollControlled = false, | ||
| 356 | - bool useRootNavigator = false, | ||
| 357 | - bool isDismissible = true, | ||
| 358 | - bool enableDrag = true, | ||
| 359 | - }) { | ||
| 360 | - assert(bottomsheet != null); | ||
| 361 | - assert(isScrollControlled != null); | ||
| 362 | - assert(useRootNavigator != null); | ||
| 363 | - assert(isDismissible != null); | ||
| 364 | - assert(enableDrag != null); | ||
| 365 | - | ||
| 366 | - return navigator.push<T>(GetModalBottomSheetRoute<T>( | ||
| 367 | - builder: (_) => bottomsheet, | ||
| 368 | - theme: Theme.of(Get.key.currentContext, shadowThemeOnly: true), | ||
| 369 | - isScrollControlled: isScrollControlled, | ||
| 370 | - barrierLabel: MaterialLocalizations.of(Get.key.currentContext) | ||
| 371 | - .modalBarrierDismissLabel, | ||
| 372 | - backgroundColor: backgroundColor ?? Colors.transparent, | ||
| 373 | - elevation: elevation, | ||
| 374 | - shape: shape, | ||
| 375 | - removeTop: ignoreSafeArea ?? true, | ||
| 376 | - clipBehavior: clipBehavior, | ||
| 377 | - isDismissible: isDismissible, | ||
| 378 | - modalBarrierColor: barrierColor, | ||
| 379 | - settings: RouteSettings(name: "bottomsheet"), | ||
| 380 | - enableDrag: enableDrag, | ||
| 381 | - )); | ||
| 382 | - } | ||
| 383 | - | ||
| 384 | - static void rawSnackbar( | ||
| 385 | - {String title, | ||
| 386 | - String message, | ||
| 387 | - Widget titleText, | ||
| 388 | - Widget messageText, | ||
| 389 | - Widget icon, | ||
| 390 | - bool instantInit = false, | ||
| 391 | - bool shouldIconPulse = true, | ||
| 392 | - double maxWidth, | ||
| 393 | - EdgeInsets margin = const EdgeInsets.all(0.0), | ||
| 394 | - EdgeInsets padding = const EdgeInsets.all(16), | ||
| 395 | - double borderRadius = 0.0, | ||
| 396 | - Color borderColor, | ||
| 397 | - double borderWidth = 1.0, | ||
| 398 | - Color backgroundColor = const Color(0xFF303030), | ||
| 399 | - Color leftBarIndicatorColor, | ||
| 400 | - List<BoxShadow> boxShadows, | ||
| 401 | - Gradient backgroundGradient, | ||
| 402 | - FlatButton mainButton, | ||
| 403 | - OnTap onTap, | ||
| 404 | - Duration duration = const Duration(seconds: 3), | ||
| 405 | - bool isDismissible = true, | ||
| 406 | - SnackDismissDirection dismissDirection = SnackDismissDirection.VERTICAL, | ||
| 407 | - bool showProgressIndicator = false, | ||
| 408 | - AnimationController progressIndicatorController, | ||
| 409 | - Color progressIndicatorBackgroundColor, | ||
| 410 | - Animation<Color> progressIndicatorValueColor, | ||
| 411 | - SnackPosition snackPosition = SnackPosition.BOTTOM, | ||
| 412 | - SnackStyle snackStyle = SnackStyle.FLOATING, | ||
| 413 | - Curve forwardAnimationCurve = Curves.easeOutCirc, | ||
| 414 | - Curve reverseAnimationCurve = Curves.easeOutCirc, | ||
| 415 | - Duration animationDuration = const Duration(seconds: 1), | ||
| 416 | - SnackStatusCallback onStatusChanged, | ||
| 417 | - double barBlur = 0.0, | ||
| 418 | - double overlayBlur = 0.0, | ||
| 419 | - Color overlayColor = Colors.transparent, | ||
| 420 | - Form userInputForm}) { | ||
| 421 | - GetBar getBar = GetBar( | ||
| 422 | - title: title, | ||
| 423 | - message: message, | ||
| 424 | - titleText: titleText, | ||
| 425 | - messageText: messageText, | ||
| 426 | - snackPosition: snackPosition, | ||
| 427 | - borderRadius: borderRadius, | ||
| 428 | - margin: margin, | ||
| 429 | - duration: duration, | ||
| 430 | - barBlur: barBlur, | ||
| 431 | - backgroundColor: backgroundColor, | ||
| 432 | - icon: icon, | ||
| 433 | - shouldIconPulse: shouldIconPulse, | ||
| 434 | - maxWidth: maxWidth, | ||
| 435 | - padding: padding, | ||
| 436 | - borderColor: borderColor, | ||
| 437 | - borderWidth: borderWidth, | ||
| 438 | - leftBarIndicatorColor: leftBarIndicatorColor, | ||
| 439 | - boxShadows: boxShadows, | ||
| 440 | - backgroundGradient: backgroundGradient, | ||
| 441 | - mainButton: mainButton, | ||
| 442 | - onTap: onTap, | ||
| 443 | - isDismissible: isDismissible, | ||
| 444 | - dismissDirection: dismissDirection, | ||
| 445 | - showProgressIndicator: showProgressIndicator ?? false, | ||
| 446 | - progressIndicatorController: progressIndicatorController, | ||
| 447 | - progressIndicatorBackgroundColor: progressIndicatorBackgroundColor, | ||
| 448 | - progressIndicatorValueColor: progressIndicatorValueColor, | ||
| 449 | - snackStyle: snackStyle, | ||
| 450 | - forwardAnimationCurve: forwardAnimationCurve, | ||
| 451 | - reverseAnimationCurve: reverseAnimationCurve, | ||
| 452 | - animationDuration: animationDuration, | ||
| 453 | - overlayBlur: overlayBlur, | ||
| 454 | - overlayColor: overlayColor, | ||
| 455 | - userInputForm: userInputForm); | ||
| 456 | - | ||
| 457 | - if (instantInit) { | ||
| 458 | - getBar.show(); | ||
| 459 | - } else { | ||
| 460 | - SchedulerBinding.instance.addPostFrameCallback((_) { | ||
| 461 | - getBar.show(); | ||
| 462 | - }); | ||
| 463 | - } | ||
| 464 | - } | ||
| 465 | - | ||
| 466 | - static void snackbar(title, message, | ||
| 467 | - {Color colorText, | ||
| 468 | - Duration duration, | ||
| 469 | - | ||
| 470 | - /// with instantInit = false you can put Get.snackbar on initState | ||
| 471 | - bool instantInit = false, | ||
| 472 | - SnackPosition snackPosition, | ||
| 473 | - Widget titleText, | ||
| 474 | - Widget messageText, | ||
| 475 | - Widget icon, | ||
| 476 | - bool shouldIconPulse, | ||
| 477 | - double maxWidth, | ||
| 478 | - EdgeInsets margin, | ||
| 479 | - EdgeInsets padding, | ||
| 480 | - double borderRadius, | ||
| 481 | - Color borderColor, | ||
| 482 | - double borderWidth, | ||
| 483 | - Color backgroundColor, | ||
| 484 | - Color leftBarIndicatorColor, | ||
| 485 | - List<BoxShadow> boxShadows, | ||
| 486 | - Gradient backgroundGradient, | ||
| 487 | - FlatButton mainButton, | ||
| 488 | - OnTap onTap, | ||
| 489 | - bool isDismissible, | ||
| 490 | - bool showProgressIndicator, | ||
| 491 | - SnackDismissDirection dismissDirection, | ||
| 492 | - AnimationController progressIndicatorController, | ||
| 493 | - Color progressIndicatorBackgroundColor, | ||
| 494 | - Animation<Color> progressIndicatorValueColor, | ||
| 495 | - SnackStyle snackStyle, | ||
| 496 | - Curve forwardAnimationCurve, | ||
| 497 | - Curve reverseAnimationCurve, | ||
| 498 | - Duration animationDuration, | ||
| 499 | - double barBlur, | ||
| 500 | - double overlayBlur, | ||
| 501 | - Color overlayColor, | ||
| 502 | - Form userInputForm}) { | ||
| 503 | - GetBar getBar = GetBar( | ||
| 504 | - titleText: (title == null) | ||
| 505 | - ? null | ||
| 506 | - : titleText ?? | ||
| 507 | - Text( | ||
| 508 | - title, | ||
| 509 | - style: TextStyle( | ||
| 510 | - color: colorText ?? theme.iconTheme.color, | ||
| 511 | - fontWeight: FontWeight.w800, | ||
| 512 | - fontSize: 16), | ||
| 513 | - ), | ||
| 514 | - messageText: messageText ?? | ||
| 515 | - Text( | ||
| 516 | - message, | ||
| 517 | - style: TextStyle( | ||
| 518 | - color: colorText ?? theme.iconTheme.color, | ||
| 519 | - fontWeight: FontWeight.w300, | ||
| 520 | - fontSize: 14), | ||
| 521 | - ), | ||
| 522 | - snackPosition: snackPosition ?? SnackPosition.TOP, | ||
| 523 | - borderRadius: borderRadius ?? 15, | ||
| 524 | - margin: margin ?? EdgeInsets.symmetric(horizontal: 10), | ||
| 525 | - duration: duration ?? Duration(seconds: 3), | ||
| 526 | - barBlur: barBlur ?? 7.0, | ||
| 527 | - backgroundColor: backgroundColor ?? Colors.grey.withOpacity(0.2), | ||
| 528 | - icon: icon, | ||
| 529 | - shouldIconPulse: shouldIconPulse ?? true, | ||
| 530 | - maxWidth: maxWidth, | ||
| 531 | - padding: padding ?? EdgeInsets.all(16), | ||
| 532 | - borderColor: borderColor, | ||
| 533 | - borderWidth: borderWidth, | ||
| 534 | - leftBarIndicatorColor: leftBarIndicatorColor, | ||
| 535 | - boxShadows: boxShadows, | ||
| 536 | - backgroundGradient: backgroundGradient, | ||
| 537 | - mainButton: mainButton, | ||
| 538 | - onTap: onTap, | ||
| 539 | - isDismissible: isDismissible ?? true, | ||
| 540 | - dismissDirection: dismissDirection ?? SnackDismissDirection.VERTICAL, | ||
| 541 | - showProgressIndicator: showProgressIndicator ?? false, | ||
| 542 | - progressIndicatorController: progressIndicatorController, | ||
| 543 | - progressIndicatorBackgroundColor: progressIndicatorBackgroundColor, | ||
| 544 | - progressIndicatorValueColor: progressIndicatorValueColor, | ||
| 545 | - snackStyle: snackStyle ?? SnackStyle.FLOATING, | ||
| 546 | - forwardAnimationCurve: forwardAnimationCurve ?? Curves.easeOutCirc, | ||
| 547 | - reverseAnimationCurve: reverseAnimationCurve ?? Curves.easeOutCirc, | ||
| 548 | - animationDuration: animationDuration ?? Duration(seconds: 1), | ||
| 549 | - overlayBlur: overlayBlur ?? 0.0, | ||
| 550 | - overlayColor: overlayColor ?? Colors.transparent, | ||
| 551 | - userInputForm: userInputForm); | ||
| 552 | - | ||
| 553 | - if (instantInit) { | ||
| 554 | - getBar.show(); | ||
| 555 | - } else { | ||
| 556 | - SchedulerBinding.instance.addPostFrameCallback((_) { | ||
| 557 | - getBar.show(); | ||
| 558 | - }); | ||
| 559 | - } | ||
| 560 | - } | ||
| 561 | - | ||
| 562 | - /// change default config of Get | ||
| 563 | - static void config( | ||
| 564 | - {bool enableLog, | ||
| 565 | - bool defaultPopGesture, | ||
| 566 | - bool defaultOpaqueRoute, | ||
| 567 | - Duration defaultDurationTransition, | ||
| 568 | - bool defaultGlobalState, | ||
| 569 | - Transition defaultTransition}) { | ||
| 570 | - if (enableLog != null) { | ||
| 571 | - _enableLog = enableLog; | ||
| 572 | - } | ||
| 573 | - if (defaultPopGesture != null) { | ||
| 574 | - _defaultPopGesture = defaultPopGesture; | ||
| 575 | - } | ||
| 576 | - if (defaultOpaqueRoute != null) { | ||
| 577 | - _defaultOpaqueRoute = defaultOpaqueRoute; | ||
| 578 | - } | ||
| 579 | - if (defaultTransition != null) { | ||
| 580 | - _defaultTransition = defaultTransition; | ||
| 581 | - } | ||
| 582 | - | ||
| 583 | - if (defaultDurationTransition != null) { | ||
| 584 | - _defaultDurationTransition = defaultDurationTransition; | ||
| 585 | - } | ||
| 586 | - | ||
| 587 | - if (defaultGlobalState != null) { | ||
| 588 | - _defaultGlobalState = defaultGlobalState; | ||
| 589 | - } | ||
| 590 | - } | ||
| 591 | - | ||
| 592 | - static GetMaterialController getController = GetMaterialController(); | ||
| 593 | - | ||
| 594 | - static changeTheme(ThemeData theme) { | ||
| 595 | - getController.setTheme(theme); | ||
| 596 | - } | ||
| 597 | - | ||
| 598 | - static restartApp() { | ||
| 599 | - getController.restartApp(); | ||
| 600 | - } | ||
| 601 | - | ||
| 602 | - static Map<int, GlobalKey<NavigatorState>> _keys = {}; | ||
| 603 | - | ||
| 604 | - static GlobalKey<NavigatorState> nestedKey(int key) { | ||
| 605 | - _keys.putIfAbsent(key, () => GlobalKey<NavigatorState>()); | ||
| 606 | - return _keys[key]; | ||
| 607 | - } | ||
| 608 | - | ||
| 609 | - static GlobalKey<NavigatorState> global(int k) { | ||
| 610 | - if (k == null) { | ||
| 611 | - return key; | ||
| 612 | - } | ||
| 613 | - if (!_keys.containsKey(k)) { | ||
| 614 | - throw 'route id not found'; | ||
| 615 | - } | ||
| 616 | - return _keys[k]; | ||
| 617 | - } | ||
| 618 | - | ||
| 619 | - //////////// INSTANCE MANAGER | ||
| 620 | - Map<dynamic, dynamic> _singl = {}; | ||
| 621 | - | ||
| 622 | - Map<dynamic, _FcBuilderFunc> _factory = {}; | ||
| 623 | - | ||
| 624 | - static void lazyPut<S>(_FcBuilderFunc function) { | ||
| 625 | - Get()._factory.putIfAbsent(S, () => function); | ||
| 626 | - } | ||
| 627 | - | ||
| 628 | - /// Inject class on Get Instance Manager | ||
| 629 | - static S put<S>( | ||
| 630 | - S dependency, { | ||
| 631 | - String name, | ||
| 632 | - bool overrideAbstract = false, | ||
| 633 | - _FcBuilderFunc<S> builder, | ||
| 634 | - }) { | ||
| 635 | - _insert( | ||
| 636 | - isSingleton: true, | ||
| 637 | - replace: overrideAbstract, | ||
| 638 | - //?? (("$S" == "${dependency.runtimeType}") == false), | ||
| 639 | - name: name, | ||
| 640 | - builder: builder ?? (() => dependency)); | ||
| 641 | - return find<S>(name: name); | ||
| 642 | - } | ||
| 643 | - | ||
| 644 | - /// Create a new instance from builder class | ||
| 645 | - /// Example | ||
| 646 | - /// Get.create(() => Repl()); | ||
| 647 | - /// Repl a = Get.find(); | ||
| 648 | - /// Repl b = Get.find(); | ||
| 649 | - /// print(a==b); (false) | ||
| 650 | - static void create<S>( | ||
| 651 | - _FcBuilderFunc<S> builder, { | ||
| 652 | - String name, | ||
| 653 | - }) { | ||
| 654 | - _insert(isSingleton: false, name: name, builder: builder); | ||
| 655 | - } | ||
| 656 | - | ||
| 657 | - static void _insert<S>({ | ||
| 658 | - bool isSingleton, | ||
| 659 | - String name, | ||
| 660 | - bool replace = true, | ||
| 661 | - _FcBuilderFunc<S> builder, | ||
| 662 | - }) { | ||
| 663 | - assert(builder != null); | ||
| 664 | - String key = _getKey(S, name); | ||
| 665 | - if (replace) { | ||
| 666 | - Get()._singl[key] = _FcBuilder<S>(isSingleton, builder); | ||
| 667 | - } else { | ||
| 668 | - Get()._singl.putIfAbsent(key, () => _FcBuilder<S>(isSingleton, builder)); | ||
| 669 | - } | ||
| 670 | - } | ||
| 671 | - | ||
| 672 | - /// Find a instance from required class | ||
| 673 | - static S find<S>({String name}) { | ||
| 674 | - if (Get.isRegistred<S>()) { | ||
| 675 | - String key = _getKey(S, name); | ||
| 676 | - _FcBuilder builder = Get()._singl[key]; | ||
| 677 | - if (builder == null) { | ||
| 678 | - if (name == null) { | ||
| 679 | - throw "class ${S.toString()} is not register"; | ||
| 680 | - } else { | ||
| 681 | - throw "class ${S.toString()} with name '$name' is not register"; | ||
| 682 | - } | ||
| 683 | - } | ||
| 684 | - return Get()._singl[key].getSependency(); | ||
| 685 | - } else { | ||
| 686 | - if (!Get()._factory.containsKey(S)) | ||
| 687 | - throw " $S not found. You need call Get.put<$S>($S()) before"; | ||
| 688 | - | ||
| 689 | - if (isLogEnable) print('[GET] $S instance was created at that time'); | ||
| 690 | - S _value = Get.put<S>(Get()._factory[S].call() as S); | ||
| 691 | - Get()._factory.remove(S); | ||
| 692 | - return _value; | ||
| 693 | - } | ||
| 694 | - } | ||
| 695 | - | ||
| 696 | - /// Remove dependency of [S] on dependency abstraction. For concrete class use Get.delete | ||
| 697 | - static void remove<S>({String name}) { | ||
| 698 | - String key = _getKey(S, name); | ||
| 699 | - _FcBuilder builder = Get()._singl[key]; | ||
| 700 | - if (builder != null) builder.dependency = null; | ||
| 701 | - if (Get()._singl.containsKey(key)) { | ||
| 702 | - print('error on remove $key'); | ||
| 703 | - } else { | ||
| 704 | - if (isLogEnable) print('[GET] $key removed from memory'); | ||
| 705 | - } | ||
| 706 | - } | ||
| 707 | - | ||
| 708 | - static String _getKey(Type type, String name) { | ||
| 709 | - return name == null ? type.toString() : type.toString() + name; | ||
| 710 | - } | ||
| 711 | - | ||
| 712 | - static bool reset() { | ||
| 713 | - Get()._singl.clear(); | ||
| 714 | - return true; | ||
| 715 | - } | ||
| 716 | - | ||
| 717 | - /// Delete class instance on [S] and clean memory | ||
| 718 | - static bool delete<S>({String name}) { | ||
| 719 | - String key = _getKey(S, name); | ||
| 720 | - | ||
| 721 | - if (!Get()._singl.containsKey(key)) { | ||
| 722 | - print('Instance $key not found'); | ||
| 723 | - return false; | ||
| 724 | - } | ||
| 725 | - Get()._singl.removeWhere((oldkey, value) => (oldkey == key)); | ||
| 726 | - if (Get()._singl.containsKey(key)) { | ||
| 727 | - print('error on remove object $key'); | ||
| 728 | - } else { | ||
| 729 | - if (isLogEnable) print('[GET] $key deleted from memory'); | ||
| 730 | - } | ||
| 731 | - return true; | ||
| 732 | - } | ||
| 733 | - | ||
| 734 | - /// check if instance is registred | ||
| 735 | - static bool isRegistred<S>({String name}) => | ||
| 736 | - Get()._singl.containsKey(_getKey(S, name)); | ||
| 737 | - | ||
| 738 | - /// give access to Routing API from GetObserver | ||
| 739 | - static Routing get routing => _routing; | ||
| 740 | - | ||
| 741 | - static RouteSettings get routeSettings => _settings; | ||
| 742 | - | ||
| 743 | - static Routing _routing; | ||
| 744 | - | ||
| 745 | - static Map<String, String> _parameters = {}; | ||
| 746 | - | ||
| 747 | - static setParameter(Map<String, String> param) { | ||
| 748 | - _parameters = param; | ||
| 749 | - } | ||
| 750 | - | ||
| 751 | - static setRouting(Routing rt) { | ||
| 752 | - _routing = rt; | ||
| 753 | - } | ||
| 754 | - | ||
| 755 | - static setSettings(RouteSettings settings) { | ||
| 756 | - _settings = settings; | ||
| 757 | - } | ||
| 758 | - | ||
| 759 | - /// give current arguments | ||
| 760 | - static get arguments => _routing.args; | ||
| 761 | - | ||
| 762 | - /// give current arguments | ||
| 763 | - static Map<String, String> get parameters => _parameters; | ||
| 764 | - | ||
| 765 | - /// interface to GetX | ||
| 766 | - RxInterface _obs; | ||
| 767 | - | ||
| 768 | - static RxInterface get obs => _get._obs; | ||
| 769 | - | ||
| 770 | - static set obs(RxInterface observer) => _get._obs = observer; | ||
| 771 | - | ||
| 772 | - /// give arguments from previous route | ||
| 773 | - static get previousArguments => _routing.previousArgs; | ||
| 774 | - | ||
| 775 | - /// give name from current route | ||
| 776 | - static get currentRoute => _routing.current; | ||
| 777 | - | ||
| 778 | - /// give name from previous route | ||
| 779 | - static get previousRoute => _routing.previous; | ||
| 780 | - | ||
| 781 | - /// check if snackbar is open | ||
| 782 | - static bool get isSnackbarOpen => _routing.isSnackbar; | ||
| 783 | - | ||
| 784 | - /// check if dialog is open | ||
| 785 | - static bool get isDialogOpen => _routing.isDialog; | ||
| 786 | - | ||
| 787 | - /// check if bottomsheet is open | ||
| 788 | - static bool get isBottomSheetOpen => _routing.isBottomSheet; | ||
| 789 | - | ||
| 790 | - /// check a raw current route | ||
| 791 | - static Route<dynamic> get rawRoute => _routing.route; | ||
| 792 | - | ||
| 793 | - /// check if log is enable | ||
| 794 | - static bool get isLogEnable => _enableLog; | ||
| 795 | - | ||
| 796 | - /// default duration of transition animation | ||
| 797 | - /// default duration work only API 2.0 | ||
| 798 | - static Duration get defaultDurationTransition => _defaultDurationTransition; | ||
| 799 | - | ||
| 800 | - /// give global state of all GetState by default | ||
| 801 | - static bool get defaultGlobalState => _defaultGlobalState; | ||
| 802 | - | ||
| 803 | - /// check if popGesture is enable | ||
| 804 | - static bool get isPopGestureEnable => _defaultPopGesture; | ||
| 805 | - | ||
| 806 | - /// check if default opaque route is enable | ||
| 807 | - static bool get isOpaqueRouteDefault => _defaultOpaqueRoute; | ||
| 808 | - | ||
| 809 | - static Transition get defaultTransition => _defaultTransition; | ||
| 810 | - | ||
| 811 | - /// give access to currentContext | ||
| 812 | - static BuildContext get context => key.currentContext; | ||
| 813 | - | ||
| 814 | - /// give access to current Overlay Context | ||
| 815 | - static BuildContext get overlayContext => key.currentState.overlay.context; | ||
| 816 | - | ||
| 817 | - /// give access to Theme.of(context) | ||
| 818 | - static ThemeData get theme => Theme.of(context); | ||
| 819 | - | ||
| 820 | - /// give access to TextTheme.of(context) | ||
| 821 | - static TextTheme get textTheme => Theme.of(context).textTheme; | ||
| 822 | - | ||
| 823 | - /// give access to Mediaquery.of(context) | ||
| 824 | - static MediaQueryData get mediaQuery => MediaQuery.of(context); | ||
| 825 | - | ||
| 826 | - /// Check if dark mode theme is enable | ||
| 827 | - static get isDarkMode => (theme.brightness == Brightness.dark); | ||
| 828 | - | ||
| 829 | - /// Check if dark mode theme is enable on platform on android Q+ | ||
| 830 | - static get isPlatformDarkMode => | ||
| 831 | - (mediaQuery.platformBrightness == Brightness.dark); | ||
| 832 | - | ||
| 833 | - /// give access to Theme.of(context).iconTheme.color | ||
| 834 | - static Color get iconColor => Theme.of(context).iconTheme.color; | ||
| 835 | - | ||
| 836 | - /// give access to MediaQuery.of(context).size.height | ||
| 837 | - static double get height => MediaQuery.of(context).size.height; | ||
| 838 | - | ||
| 839 | - /// give access to MediaQuery.of(context).size.width | ||
| 840 | - static double get width => MediaQuery.of(context).size.width; | ||
| 841 | -} | ||
| 842 | - | ||
| 843 | -/// It replaces the Flutter Navigator, but needs no context. | ||
| 844 | -/// You can to use navigator.push(YourRoute()) rather Navigator.push(context, YourRoute()); | ||
| 845 | -NavigatorState get navigator => Get.key.currentState; | ||
| 846 | - | ||
| 847 | -class _FcBuilder<S> { | ||
| 848 | - bool isSingleton; | ||
| 849 | - _FcBuilderFunc builderFunc; | ||
| 850 | - S dependency; | ||
| 851 | - | ||
| 852 | - _FcBuilder(this.isSingleton, this.builderFunc); | ||
| 853 | - | ||
| 854 | - S getSependency() { | ||
| 855 | - if (isSingleton) { | ||
| 856 | - if (dependency == null) { | ||
| 857 | - dependency = builderFunc() as S; | ||
| 858 | - } | ||
| 859 | - return dependency; | ||
| 860 | - } else { | ||
| 861 | - return builderFunc() as S; | ||
| 862 | - } | ||
| 863 | - } | ||
| 864 | -} | ||
| 865 | - | ||
| 866 | -typedef _FcBuilderFunc<S> = S Function(); |
-
Please register or login to post a comment