Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
fluttertpc_get
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Jonatas
2020-09-15 17:51:09 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a8430d0d8051154e81f2000aa404c0cd4cd4eaaf
a8430d0d
1 parent
baf559dd
full split from contextless tools
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
133 additions
and
83 deletions
example/lib/main.dart
lib/src/core/get_interface.dart
lib/src/instance/get_instance.dart
lib/src/navigation/extension_navigation.dart
lib/src/navigation/root/root_controller.dart
lib/src/navigation/root/root_widget.dart
lib/src/utils/extensions/internacionalization.dart
example/lib/main.dart
View file @
a8430d0
...
...
@@ -16,7 +16,6 @@ class MyApp extends StatelessWidget {
return
GetMaterialApp
(
debugShowCheckedModeBanner:
false
,
enableLog:
true
,
// locale: Locale('PT'),
logWriterCallback:
Logger
.
write
,
initialRoute:
AppPages
.
INITIAL
,
getPages:
AppPages
.
routes
,
...
...
lib/src/core/get_interface.dart
View file @
a8430d0
import
'package:flutter/material.dart'
;
import
'../../utils.dart'
;
import
'../navigation/root/parse_route.dart'
;
import
'../navigation/root/root_controller.dart'
;
import
'../navigation/routes/custom_transition.dart'
;
import
'../navigation/routes/observers/route_observer.dart'
;
import
'../navigation/routes/transitions_type.dart'
;
/// Use Get.to instead of Navigator.push, Get.off instead
/// of Navigator.pushReplacement,
/// Get.offAll instead of Navigator.pushAndRemoveUntil.
...
...
@@ -16,38 +7,4 @@ import '../navigation/routes/transitions_type.dart';
/// No need to pass any context to Get, just put the name of the route inside
/// the parentheses and the magic will occur.
abstract
class
GetInterface
{
bool
defaultPopGesture
=
GetPlatform
.
isIOS
;
bool
defaultOpaqueRoute
=
true
;
Transition
defaultTransition
;
Duration
defaultTransitionDuration
=
Duration
(
milliseconds:
400
);
Curve
defaultTransitionCurve
=
Curves
.
easeOutQuad
;
Curve
defaultDialogTransitionCurve
=
Curves
.
easeOutQuad
;
Duration
defaultDialogTransitionDuration
=
Duration
(
milliseconds:
400
);
bool
defaultGlobalState
=
true
;
RouteSettings
settings
;
String
defaultSeparator
=
'_'
;
final
routing
=
Routing
();
Map
<
String
,
String
>
parameters
=
{};
ParseRouteTree
routeTree
;
CustomTransition
customTransition
;
GetMaterialController
getxController
=
GetMaterialController
();
Locale
locale
;
Locale
fallbackLocale
;
GlobalKey
<
NavigatorState
>
key
=
GlobalKey
<
NavigatorState
>();
Map
<
int
,
GlobalKey
<
NavigatorState
>>
keys
=
{};
Map
<
String
,
Map
<
String
,
String
>>
translations
=
{};
}
abstract
class
GetInterface
{}
...
...
lib/src/instance/get_instance.dart
View file @
a8430d0
...
...
@@ -21,6 +21,8 @@ class GetInstance {
static
GetInstance
_getInstance
;
static
final
config
=
GetConfig
();
/// Holds references to every registered Instance when using
/// [Get.put()]
static
final
Map
<
String
,
_InstanceBuilderFactory
>
_singl
=
{};
...
...
lib/src/navigation/extension_navigation.dart
View file @
a8430d0
import
'package:flutter/material.dart'
;
import
'package:flutter/scheduler.dart'
;
import
'../../get.dart'
;
import
'../../instance_manager.dart'
;
import
'../../route_manager.dart'
;
import
'../core/get_interface.dart'
;
import
'../core/log.dart'
;
import
'dialog/dialog_route.dart'
;
import
'root/parse_route.dart'
;
import
'root/root_controller.dart'
;
import
'routes/bindings_interface.dart'
;
/// It replaces the Flutter Navigator, but needs no context.
...
...
@@ -640,6 +642,7 @@ extension GetNavigation on GetInterface {
bool
useRootNavigator
=
false
,
bool
isDismissible
=
true
,
bool
enableDrag
=
true
,
RouteSettings
settings
,
})
{
assert
(
bottomsheet
!=
null
);
assert
(
persistent
!=
null
);
...
...
@@ -892,26 +895,22 @@ extension GetNavigation on GetInterface {
GetConfig
.
log
=
logWriterCallback
;
}
if
(
defaultPopGesture
!=
null
)
{
this
.
defaultPopGesture
=
defaultPopGesture
;
getxController
.
defaultPopGesture
=
defaultPopGesture
;
}
if
(
defaultOpaqueRoute
!=
null
)
{
this
.
defaultOpaqueRoute
=
defaultOpaqueRoute
;
getxController
.
defaultOpaqueRoute
=
defaultOpaqueRoute
;
}
if
(
defaultTransition
!=
null
)
{
this
.
defaultTransition
=
defaultTransition
;
getxController
.
defaultTransition
=
defaultTransition
;
}
if
(
defaultDurationTransition
!=
null
)
{
defaultTransitionDuration
=
defaultDurationTransition
;
}
if
(
defaultGlobalState
!=
null
)
{
this
.
defaultGlobalState
=
defaultGlobalState
;
getxController
.
defaultTransitionDuration
=
defaultDurationTransition
;
}
}
void
updateLocale
(
Locale
l
)
{
locale
=
l
;
Get
.
locale
=
l
;
forceAppUpdate
();
}
...
...
@@ -924,20 +923,6 @@ extension GetNavigation on GetInterface {
(
context
as
Element
).
visitChildren
(
rebuild
);
}
void
addTranslations
(
Map
<
String
,
Map
<
String
,
String
>>
tr
)
{
translations
.
addAll
(
tr
);
}
void
appendTranslations
(
Map
<
String
,
Map
<
String
,
String
>>
tr
)
{
tr
.
forEach
((
key
,
map
)
{
if
(
Get
.
translations
.
containsKey
(
key
))
{
Get
.
translations
[
key
].
addAll
(
map
);
}
else
{
Get
.
translations
[
key
]
=
map
;
}
});
}
void
changeTheme
(
ThemeData
theme
)
{
getxController
.
setTheme
(
theme
);
}
...
...
@@ -947,7 +932,7 @@ extension GetNavigation on GetInterface {
}
GlobalKey
<
NavigatorState
>
addKey
(
GlobalKey
<
NavigatorState
>
newKey
)
{
key
=
newKey
;
getxController
.
key
=
newKey
;
return
key
;
}
...
...
@@ -966,13 +951,11 @@ extension GetNavigation on GetInterface {
return
keys
[
k
];
}
RouteSettings
get
routeSettings
=>
settings
;
// FIXME: wouldn't a direct set suffice here?
// ignore: use_setters_to_change_properties
void
setSettings
(
RouteSettings
settings
)
{
this
.
settings
=
settings
;
}
@Deprecated
(
'''
Since version 2.8 it is possible to access the properties
[Get.arguments] and [Get.currentRoute] directly.
[routeSettings] is useless and should not be used.'''
)
RouteSettings
get
routeSettings
=>
null
;
/// give current arguments
dynamic
get
arguments
=>
routing
.
args
;
...
...
@@ -1034,4 +1017,43 @@ extension GetNavigation on GetInterface {
/// give access to Immutable MediaQuery.of(context).size.width
double
get
width
=>
MediaQuery
.
of
(
context
).
size
.
width
;
GlobalKey
<
NavigatorState
>
get
key
=>
getxController
.
key
;
Map
<
int
,
GlobalKey
<
NavigatorState
>>
get
keys
=>
getxController
.
keys
;
GetMaterialController
get
rootController
=>
getxController
;
bool
get
defaultPopGesture
=>
getxController
.
defaultPopGesture
;
bool
get
defaultOpaqueRoute
=>
getxController
.
defaultOpaqueRoute
;
Transition
get
defaultTransition
=>
getxController
.
defaultTransition
;
Duration
get
defaultTransitionDuration
{
return
getxController
.
defaultDialogTransitionDuration
;
}
Curve
get
defaultTransitionCurve
=>
getxController
.
defaultTransitionCurve
;
Curve
get
defaultDialogTransitionCurve
{
return
getxController
.
defaultDialogTransitionCurve
;
}
Duration
get
defaultDialogTransitionDuration
{
return
getxController
.
defaultDialogTransitionDuration
;
}
Routing
get
routing
=>
getxController
.
routing
;
Map
<
String
,
String
>
get
parameters
=>
getxController
.
parameters
;
set
parameters
(
Map
<
String
,
String
>
newParameters
)
=>
getxController
.
parameters
=
newParameters
;
ParseRouteTree
get
routeTree
=>
getxController
.
routeTree
;
set
routeTree
(
ParseRouteTree
tree
)
=>
getxController
.
routeTree
=
tree
;
CustomTransition
get
customTransition
=>
getxController
.
customTransition
;
set
customTransition
(
CustomTransition
newTransition
)
=>
getxController
.
customTransition
=
newTransition
;
static
GetMaterialController
getxController
=
GetMaterialController
();
}
...
...
lib/src/navigation/root/root_controller.dart
View file @
a8430d0
import
'package:flutter/material.dart'
;
import
'../../state_manager/simple/get_state.dart'
;
import
'../../utils/platform/platform.dart'
;
import
'../routes/custom_transition.dart'
;
import
'../routes/observers/route_observer.dart'
;
import
'../routes/transitions_type.dart'
;
import
'parse_route.dart'
;
class
GetMaterialController
extends
GetxController
{
Key
key
;
Key
uni
key
;
ThemeData
theme
;
ThemeMode
themeMode
;
bool
defaultPopGesture
=
GetPlatform
.
isIOS
;
bool
defaultOpaqueRoute
=
true
;
Transition
defaultTransition
;
Duration
defaultTransitionDuration
=
Duration
(
milliseconds:
400
);
Curve
defaultTransitionCurve
=
Curves
.
easeOutQuad
;
Curve
defaultDialogTransitionCurve
=
Curves
.
easeOutQuad
;
Duration
defaultDialogTransitionDuration
=
Duration
(
milliseconds:
400
);
final
routing
=
Routing
();
Map
<
String
,
String
>
parameters
=
{};
ParseRouteTree
routeTree
;
CustomTransition
customTransition
;
GlobalKey
<
NavigatorState
>
key
=
GlobalKey
<
NavigatorState
>();
Map
<
int
,
GlobalKey
<
NavigatorState
>>
keys
=
{};
void
setTheme
(
ThemeData
value
)
{
theme
=
value
;
update
();
...
...
@@ -17,7 +44,7 @@ class GetMaterialController extends GetxController {
}
void
restartApp
()
{
key
=
UniqueKey
();
uni
key
=
UniqueKey
();
update
();
}
}
...
...
lib/src/navigation/root/root_widget.dart
View file @
a8430d0
...
...
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import
'../../../get.dart'
;
import
'../../core/log.dart'
;
import
'../../instance/get_instance.dart'
;
import
'../extension_navigation.dart'
;
import
'../routes/get_route.dart'
;
import
'root_controller.dart'
;
import
'smart_management.dart'
;
...
...
@@ -181,7 +182,7 @@ class GetMaterialApp extends StatelessWidget {
@override
Widget
build
(
BuildContext
context
)
{
return
GetBuilder
<
GetMaterialController
>(
init:
Get
.
getx
Controller
,
init:
Get
.
root
Controller
,
dispose:
(
d
)
{
onDispose
?.
call
();
},
...
...
@@ -191,9 +192,9 @@ class GetMaterialApp extends StatelessWidget {
if
(
fallbackLocale
!=
null
)
Get
.
fallbackLocale
=
fallbackLocale
;
if
(
translations
!=
null
)
{
Get
.
translations
=
translations
.
keys
;
Get
.
addTranslations
(
translations
.
keys
)
;
}
else
if
(
translationsKeys
!=
null
)
{
Get
.
translations
=
translationsKeys
;
Get
.
addTranslations
(
translationsKeys
)
;
}
Get
.
customTransition
=
customTransition
;
...
...
@@ -211,12 +212,12 @@ class GetMaterialApp extends StatelessWidget {
defaultPopGesture:
popGesture
??
Get
.
isPopGestureEnable
,
defaultDurationTransition:
transitionDuration
??
Get
.
defaultTransitionDuration
,
defaultGlobalState:
defaultGlobalState
??
Get
.
defaultGlobalState
,
);
},
builder:
(
_
)
{
return
MaterialApp
(
key:
key
,
key:
_
.
uni
key
,
navigatorKey:
(
navigatorKey
==
null
?
Get
.
key
:
Get
.
addKey
(
navigatorKey
)),
home:
home
,
...
...
lib/src/utils/extensions/internacionalization.dart
View file @
a8430d0
import
'dart:ui'
;
import
'../../core/get_interface.dart'
;
import
'../../core/get_main.dart'
;
extension
Trans
on
String
{
...
...
@@ -49,3 +51,43 @@ extension Trans on String {
return
key
;
}
}
class
_IntlHost
{
Locale
locale
;
Locale
fallbackLocale
;
Map
<
String
,
Map
<
String
,
String
>>
translations
=
{};
}
extension
LocalesIntl
on
GetInterface
{
static
final
_intlHost
=
_IntlHost
();
Locale
get
locale
=>
_intlHost
.
locale
;
Locale
get
fallbackLocale
=>
_intlHost
.
fallbackLocale
;
set
locale
(
Locale
newLocale
)
{
_intlHost
.
locale
=
newLocale
;
}
set
fallbackLocale
(
Locale
newLocale
)
{
_intlHost
.
fallbackLocale
=
newLocale
;
}
Map
<
String
,
Map
<
String
,
String
>>
get
translations
=>
_intlHost
.
translations
;
void
addTranslations
(
Map
<
String
,
Map
<
String
,
String
>>
tr
)
{
translations
.
addAll
(
tr
);
}
void
appendTranslations
(
Map
<
String
,
Map
<
String
,
String
>>
tr
)
{
tr
.
forEach
((
key
,
map
)
{
if
(
translations
.
containsKey
(
key
))
{
translations
[
key
].
addAll
(
map
);
}
else
{
translations
[
key
]
=
map
;
}
});
}
}
...
...
Please
register
or
login
to post a comment