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
Jonny Borges
2021-07-30 20:53:57 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
932eb08931f4ddf06b8f85a7fede1543a803fe8d
932eb089
1 parent
b8d9395c
update to 4.3.4
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
134 additions
and
40 deletions
CHANGELOG.md
README.md
lib/get.dart
lib/get_common/get_reset.dart
lib/get_instance/src/extension_instance.dart
lib/get_instance/src/get_instance.dart
lib/get_navigation/src/extension_navigation.dart
lib/get_navigation/src/nav2/get_router_delegate.dart
lib/get_navigation/src/router_report.dart
lib/get_utils/src/extensions/internacionalization.dart
pubspec.yaml
CHANGELOG.md
View file @
932eb08
## [4.3.4]
-
Improve docs
## [4.3.3]
-
Fix Get.reset
...
...
README.md
View file @
932eb08
...
...
@@ -1097,6 +1097,74 @@ The only way to actually delete a `GetxService`, is with `Get.reset()` which is
"Hot Reboot" of your app. So remember, if you need absolute persistence of a class instance during the
lifetime of your app, use
`GetxService`
.
### Tests
You can test your controllers like any other class, including their lifecycles:
```
dart
class
Controller
extends
GetxController
{
@override
void
onInit
()
{
super
.
onInit
();
//Change value to name2
name
.
value
=
'name2'
;
}
@override
void
onClose
()
{
name
.
value
=
''
;
super
.
onClose
();
}
final
name
=
'name1'
.
obs
;
void
changeName
()
=>
name
.
value
=
'name3'
;
}
void
main
(
)
{
test
(
'''
Test the state of the reactive variable "name" across all of its lifecycles'''
,
()
{
/// You can test the controller without the lifecycle,
/// but it's not recommended unless you're not using
/// GetX dependency injection
final
controller
=
Controller
();
expect
(
controller
.
name
.
value
,
'name1'
);
/// If you are using it, you can test everything,
/// including the state of the application after each lifecycle.
Get
.
put
(
controller
);
// onInit was called
expect
(
controller
.
name
.
value
,
'name2'
);
/// Test your functions
controller
.
changeName
();
expect
(
controller
.
name
.
value
,
'name3'
);
/// onClose was called
Get
.
delete
<
Controller
>();
expect
(
controller
.
name
.
value
,
''
);
});
}
```
#### Tips
##### Mockito or mocktail
If you need to mock your GetxController/GetxService, you should extend GetxController, and mixin it with Mock, that way
```
dart
class
NotificationServiceMock
extends
GetxService
with
Mock
implements
NotificationService
{}
```
##### Using Get.reset()
If you are testing widgets, or test groups, use Get.reset at the end of your test or in tearDown to reset all settings from your previous test.
##### Get.testMode
if you are using your navigation in your controllers, use
`Get.testMode = true`
at the beginning of your main.
# Breaking changes from 2.0
1- Rx types:
...
...
lib/get.dart
View file @
932eb08
...
...
@@ -3,6 +3,7 @@
/// injection, and route management in a quick and practical way.
library
get
;
export
'get_common/get_reset.dart'
;
export
'get_connect/connect.dart'
;
export
'get_core/get_core.dart'
;
export
'get_instance/get_instance.dart'
;
...
...
lib/get_common/get_reset.dart
0 → 100644
View file @
932eb08
import
'../get.dart'
;
extension
GetResetExt
on
GetInterface
{
void
reset
(
{
@deprecated
bool
clearFactory
=
true
,
bool
clearRouteBindings
=
true
})
{
GetInstance
().
resetInstance
(
clearRouteBindings:
clearRouteBindings
);
Get
.
clearRouteTree
();
Get
.
clearTranslations
();
Get
.
resetRootNavigator
();
}
}
...
...
lib/get_instance/src/extension_instance.dart
View file @
932eb08
...
...
@@ -95,14 +95,14 @@ extension Inst on GetInterface {
/// - [clearFactory] clears the callbacks registered by `Get.lazyPut()`
/// - [clearRouteBindings] clears Instances associated with Routes when using
/// [GetMaterialApp].
bool
reset
(
{
@deprecated
bool
clearFactory
=
true
,
@deprecated
bool
clearRouteBindings
=
true
})
=>
GetInstance
().
reset
(
// ignore: deprecated_member_use_from_same_package
clearFactory:
clearFactory
,
// ignore: deprecated_member_use_from_same_package
clearRouteBindings:
clearRouteBindings
);
// bool reset(
// {@deprecated bool clearFactory = true,
// @deprecated bool clearRouteBindings = true}) =>
// GetInstance().reset(
// // ignore: deprecated_member_use_from_same_package
// clearFactory: clearFactory,
// // ignore: deprecated_member_use_from_same_package
// clearRouteBindings: clearRouteBindings);
/// Deletes the `Instance<S>`, cleaning the memory and closes any open
/// controllers (`DisposableInterface`).
...
...
lib/get_instance/src/get_instance.dart
View file @
932eb08
...
...
@@ -290,9 +290,8 @@ class GetInstance {
/// [clearFactory] clears the callbacks registered by [lazyPut]
/// [clearRouteBindings] clears Instances associated with routes.
///
bool
reset
(
{
@deprecated
bool
clearFactory
=
true
,
@deprecated
bool
clearRouteBindings
=
true
})
{
bool
resetInstance
(
{
@deprecated
bool
clearFactory
=
true
,
bool
clearRouteBindings
=
true
})
{
// if (clearFactory) _factory.clear();
// deleteAll(force: true);
if
(
clearRouteBindings
)
RouterReportManager
.
clearRouteKeys
();
...
...
lib/get_navigation/src/extension_navigation.dart
View file @
932eb08
...
...
@@ -1014,17 +1014,17 @@ you can only use widgets and widget functions here''';
Get
.
log
=
logWriterCallback
;
}
if
(
defaultPopGesture
!=
null
)
{
getxController
.
defaultPopGesture
=
defaultPopGesture
;
_
getxController
.
defaultPopGesture
=
defaultPopGesture
;
}
if
(
defaultOpaqueRoute
!=
null
)
{
getxController
.
defaultOpaqueRoute
=
defaultOpaqueRoute
;
_
getxController
.
defaultOpaqueRoute
=
defaultOpaqueRoute
;
}
if
(
defaultTransition
!=
null
)
{
getxController
.
defaultTransition
=
defaultTransition
;
_
getxController
.
defaultTransition
=
defaultTransition
;
}
if
(
defaultDurationTransition
!=
null
)
{
getxController
.
defaultTransitionDuration
=
defaultDurationTransition
;
_
getxController
.
defaultTransitionDuration
=
defaultDurationTransition
;
}
}
...
...
@@ -1050,18 +1050,18 @@ you can only use widgets and widget functions here''';
engine
!.
performReassemble
();
}
void
appUpdate
()
=>
getxController
.
update
();
void
appUpdate
()
=>
_
getxController
.
update
();
void
changeTheme
(
ThemeData
theme
)
{
getxController
.
setTheme
(
theme
);
_
getxController
.
setTheme
(
theme
);
}
void
changeThemeMode
(
ThemeMode
themeMode
)
{
getxController
.
setThemeMode
(
themeMode
);
_
getxController
.
setThemeMode
(
themeMode
);
}
GlobalKey
<
NavigatorState
>?
addKey
(
GlobalKey
<
NavigatorState
>
newKey
)
{
return
getxController
.
addKey
(
newKey
);
return
_
getxController
.
addKey
(
newKey
);
}
GlobalKey
<
NavigatorState
>?
nestedKey
(
dynamic
key
)
{
...
...
@@ -1206,45 +1206,49 @@ you can only use widgets and widget functions here''';
// /// give access to Immutable MediaQuery.of(context).size.width
// double get width => MediaQuery.of(context).size.width;
GlobalKey
<
NavigatorState
>
get
key
=>
getxController
.
key
;
GlobalKey
<
NavigatorState
>
get
key
=>
_
getxController
.
key
;
Map
<
dynamic
,
GlobalKey
<
NavigatorState
>>
get
keys
=>
getxController
.
keys
;
Map
<
dynamic
,
GlobalKey
<
NavigatorState
>>
get
keys
=>
_
getxController
.
keys
;
GetMaterialController
get
rootController
=>
getxController
;
GetMaterialController
get
rootController
=>
_
getxController
;
bool
get
defaultPopGesture
=>
getxController
.
defaultPopGesture
;
bool
get
defaultOpaqueRoute
=>
getxController
.
defaultOpaqueRoute
;
bool
get
defaultPopGesture
=>
_getxController
.
defaultPopGesture
;
bool
get
defaultOpaqueRoute
=>
_getxController
.
defaultOpaqueRoute
;
Transition
?
get
defaultTransition
=>
getxController
.
defaultTransition
;
Transition
?
get
defaultTransition
=>
_
getxController
.
defaultTransition
;
Duration
get
defaultTransitionDuration
{
return
getxController
.
defaultTransitionDuration
;
return
_
getxController
.
defaultTransitionDuration
;
}
Curve
get
defaultTransitionCurve
=>
getxController
.
defaultTransitionCurve
;
Curve
get
defaultTransitionCurve
=>
_
getxController
.
defaultTransitionCurve
;
Curve
get
defaultDialogTransitionCurve
{
return
getxController
.
defaultDialogTransitionCurve
;
return
_
getxController
.
defaultDialogTransitionCurve
;
}
Duration
get
defaultDialogTransitionDuration
{
return
getxController
.
defaultDialogTransitionDuration
;
return
_
getxController
.
defaultDialogTransitionDuration
;
}
Routing
get
routing
=>
getxController
.
routing
;
Routing
get
routing
=>
_
getxController
.
routing
;
Map
<
String
,
String
?>
get
parameters
=>
getxController
.
parameters
;
Map
<
String
,
String
?>
get
parameters
=>
_
getxController
.
parameters
;
set
parameters
(
Map
<
String
,
String
?>
newParameters
)
=>
getxController
.
parameters
=
newParameters
;
_
getxController
.
parameters
=
newParameters
;
CustomTransition
?
get
customTransition
=>
getxController
.
customTransition
;
CustomTransition
?
get
customTransition
=>
_
getxController
.
customTransition
;
set
customTransition
(
CustomTransition
?
newTransition
)
=>
getxController
.
customTransition
=
newTransition
;
_
getxController
.
customTransition
=
newTransition
;
bool
get
testMode
=>
getxController
.
testMode
;
set
testMode
(
bool
isTest
)
=>
getxController
.
testMode
=
isTest
;
bool
get
testMode
=>
_getxController
.
testMode
;
set
testMode
(
bool
isTest
)
=>
_getxController
.
testMode
=
isTest
;
static
GetMaterialController
getxController
=
GetMaterialController
();
void
resetRootNavigator
()
{
_getxController
=
GetMaterialController
();
}
static
GetMaterialController
_getxController
=
GetMaterialController
();
}
extension
NavTwoExt
on
GetInterface
{
...
...
@@ -1252,6 +1256,10 @@ extension NavTwoExt on GetInterface {
routeTree
.
addRoutes
(
getPages
);
}
void
clearRouteTree
()
{
_routeTree
.
routes
.
clear
();
}
static
late
final
_routeTree
=
ParseRouteTree
(
routes:
[]);
ParseRouteTree
get
routeTree
=>
_routeTree
;
...
...
lib/get_navigation/src/nav2/get_router_delegate.dart
View file @
932eb08
...
...
@@ -57,8 +57,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig>
final
List
<
NavigatorObserver
>?
navigatorObservers
;
final
TransitionDelegate
<
dynamic
>?
transitionDelegate
;
GlobalKey
<
NavigatorState
>
get
navigatorKey
=>
GetNavigation
.
getxController
.
key
;
GlobalKey
<
NavigatorState
>
get
navigatorKey
=>
Get
.
key
;
GetDelegate
({
GetPage
?
notFoundRoute
,
...
...
lib/get_navigation/src/router_report.dart
View file @
932eb08
...
...
@@ -34,6 +34,7 @@ class RouterReportManager<T> {
static
void
clearRouteKeys
()
{
_routesKey
.
clear
();
_routesByCreate
.
clear
();
}
static
void
appendRouteByCreate
(
GetLifeCycleBase
i
)
{
...
...
lib/get_utils/src/extensions/internacionalization.dart
View file @
932eb08
...
...
@@ -96,6 +96,10 @@ extension LocalesIntl on GetInterface {
translations
.
addAll
(
tr
);
}
void
clearTranslations
()
{
translations
.
clear
();
}
void
appendTranslations
(
Map
<
String
,
Map
<
String
,
String
>>
tr
)
{
tr
.
forEach
((
key
,
map
)
{
if
(
translations
.
containsKey
(
key
))
{
...
...
pubspec.yaml
View file @
932eb08
name
:
get
description
:
Open screens/snackbars/dialogs without context, manage states and inject dependencies easily with GetX.
version
:
4.3.
3
version
:
4.3.
4
homepage
:
https://github.com/jonataslaw/getx
environment
:
...
...
Please
register
or
login
to post a comment