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
2020-07-01 16:18:17 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2020-07-01 16:18:17 -0300
Commit
60638109cb3c49286807c6e91bb651ab4d5ac9e2
60638109
1 parent
221b439e
Bump version to 3.2
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
88 additions
and
27 deletions
CHANGELOG.md
lib/src/get_main.dart
lib/src/instance/get_instance.dart
lib/src/rx/rx_impl.dart
lib/src/state/get_state.dart
pubspec.yaml
CHANGELOG.md
View file @
6063810
## [3.2.0]
-
Improve GetBuilder ram usage
-
Added method update to Rx
Now you no longer need to make an entire class reactive to get an element update from it, you can simply call the update method of its instance, like this:
```
dart
class
User
{
User
(
this
.
name
=
''
,
this
.
age
=
0
);
String
name
;
int
age
;
}
final
user
=
User
().
obs
;
Obx
(()=>
Text
(
"Name
${user.value.name}
: Age:
${user.value.age}
"
))
// To update:
user
.
update
((
user
){
user
.
name
=
'Jonny'
;
user
.
age
=
18
;
});
```
Now is also possible to access a value without using the ".value". Just open and close parentheses.
In the previous example, you could do:
```
dart
user
().
name
;
// before: user.value.name
```
And it is also possible to set a value without using the value, inserting the value directly into the variable.
```
dart
user
(
User
(
'João'
,
35
));
// before: user.value = User('João', 35)
```
Added fenix mode to Get.lazyPut.
## [3.1.4]
-
Update readme banner
...
...
lib/src/get_main.dart
View file @
6063810
...
...
@@ -48,16 +48,15 @@ class GetImpl implements GetService {
Bindings
binding
,
preventDuplicates
=
true
,
bool
popGesture
})
{
if
(
preventDuplicates
&&
'/'
+
page
.
toString
().
toLowerCase
()
==
currentRoute
)
{
if
(
preventDuplicates
&&
'/
${page.runtimeType}
'
==
currentRoute
)
{
return
null
;
}
return
global
(
id
).
currentState
.
push
(
GetPageRoute
(
opaque:
opaque
??
true
,
page:
()
=>
page
,
settings:
RouteSettings
(
name:
'/'
+
page
.
toString
().
toLowerCase
(),
arguments:
arguments
),
settings:
RouteSettings
(
name:
'/
${page.runtimeType}
'
,
arguments:
arguments
),
popGesture:
popGesture
??
defaultPopGesture
,
transition:
transition
??
defaultTransition
,
fullscreenDialog:
fullscreenDialog
,
...
...
@@ -183,16 +182,15 @@ class GetImpl implements GetService {
bool
fullscreenDialog
=
false
,
preventDuplicates
=
true
,
Duration
duration
})
{
if
(
preventDuplicates
&&
'/'
+
page
.
toString
().
toLowerCase
()
==
currentRoute
)
{
if
(
preventDuplicates
&&
'/
${page.runtimeType}
'
==
currentRoute
)
{
return
null
;
}
return
global
(
id
).
currentState
.
pushReplacement
(
GetPageRoute
(
opaque:
opaque
??
true
,
page:
()
=>
page
,
binding:
binding
,
settings:
RouteSettings
(
name:
'/'
+
page
.
toString
().
toLowerCase
(),
arguments:
arguments
),
settings:
RouteSettings
(
name:
'/
${page.runtimeType}
'
,
arguments:
arguments
),
fullscreenDialog:
fullscreenDialog
,
popGesture:
popGesture
??
defaultPopGesture
,
transition:
transition
??
defaultTransition
,
...
...
@@ -218,9 +216,8 @@ class GetImpl implements GetService {
popGesture:
popGesture
??
defaultPopGesture
,
page:
()
=>
page
,
binding:
binding
,
settings:
RouteSettings
(
name:
'/'
+
page
.
runtimeType
.
toString
().
toLowerCase
(),
arguments:
arguments
),
settings:
RouteSettings
(
name:
'/
${page.runtimeType}
'
,
arguments:
arguments
),
fullscreenDialog:
fullscreenDialog
,
transition:
transition
??
defaultTransition
,
duration:
duration
??
defaultDurationTransition
,
...
...
lib/src/instance/get_instance.dart
View file @
6063810
...
...
@@ -5,13 +5,19 @@ import 'package:get/src/typedefs/typedefs.dart';
class
GetConfig
{
//////////// INSTANCE MANAGER
static
Map
<
dynamic
,
dynamic
>
_singl
=
{};
static
Map
<
dynamic
,
FcBuilderFunc
>
_factory
=
{};
static
Map
<
dynamic
,
Lazy
>
_factory
=
{};
static
Map
<
String
,
String
>
routesKey
=
{};
static
SmartManagement
smartManagement
=
SmartManagement
.
full
;
static
bool
isLogEnable
=
true
;
static
String
currentRoute
;
}
class
Lazy
{
Lazy
(
this
.
builder
,
this
.
fenix
);
bool
fenix
;
FcBuilderFunc
builder
;
}
class
GetInstance
{
factory
GetInstance
()
{
if
(
_getInstance
==
null
)
_getInstance
=
GetInstance
.
_
();
...
...
@@ -20,9 +26,10 @@ class GetInstance {
GetInstance
.
_
();
static
GetInstance
_getInstance
;
void
lazyPut
<
S
>(
FcBuilderFunc
builder
,
{
String
tag
})
{
void
lazyPut
<
S
>(
FcBuilderFunc
builder
,
{
String
tag
,
bool
fenix
=
false
})
{
String
key
=
_getKey
(
S
,
tag
);
GetConfig
.
_factory
.
putIfAbsent
(
key
,
()
=>
builder
);
GetConfig
.
_factory
.
putIfAbsent
(
key
,
()
=>
Lazy
(
builder
,
fenix
));
}
Future
<
S
>
putAsync
<
S
>(
FcBuilderFuncAsync
<
S
>
builder
,
...
...
@@ -154,7 +161,7 @@ class GetInstance {
if
(
GetConfig
.
isLogEnable
)
print
(
'[GET]
$S
instance was created at that time'
);
S
_value
=
put
<
S
>(
GetConfig
.
_factory
[
key
].
call
()
as
S
);
S
_value
=
put
<
S
>(
GetConfig
.
_factory
[
key
].
builder
()
as
S
);
if
(!
isDependencyInit
<
S
>()
&&
GetConfig
.
smartManagement
!=
SmartManagement
.
onlyBuilder
)
{
...
...
@@ -163,8 +170,10 @@ class GetInstance {
}
if
(
GetConfig
.
smartManagement
!=
SmartManagement
.
keepFactory
)
{
if
(!
GetConfig
.
_factory
[
key
].
fenix
)
{
GetConfig
.
_factory
.
remove
(
key
);
}
}
if
(
callInit
)
{
initController
<
S
>(
tag:
tag
);
...
...
lib/src/rx/rx_impl.dart
View file @
6063810
import
'dart:async'
;
import
'dart:collection'
;
import
'rx_interface.dart'
;
class
_RxImpl
<
T
>
implements
RxInterface
<
T
>
{
StreamController
<
T
>
subject
=
StreamController
<
T
>.
broadcast
();
Map
<
Stream
<
T
>,
StreamSubscription
>
_subscriptions
=
Map
();
HashMap
<
Stream
<
T
>,
StreamSubscription
>
_subscriptions
=
HashMap
<
Stream
<
T
>,
StreamSubscription
>();
T
_value
;
T
get
value
{
...
...
@@ -13,6 +15,18 @@ class _RxImpl<T> implements RxInterface<T> {
return
_value
;
}
T
call
([
T
v
])
{
if
(
v
!=
null
)
{
this
.
value
=
v
;
}
return
this
.
value
;
}
void
update
(
void
fn
(
T
value
))
{
fn
(
value
);
subject
.
add
(
value
);
}
String
get
string
=>
value
.
toString
();
close
()
{
...
...
@@ -354,6 +368,11 @@ class RxList<E> extends Iterable<E> implements RxInterface<E> {
add
(
item
);
}
void
update
(
void
fn
(
Iterable
<
E
>
value
))
{
fn
(
value
);
subject
.
add
(
null
);
}
/// Replaces all existing items of this list with [items]
void
assignAll
(
Iterable
<
E
>
items
)
{
clear
();
...
...
@@ -473,5 +492,5 @@ extension ListExtension<E> on List<E> {
}
extension
RxT
<
T
>
on
T
{
Rx
<
T
>
get
obs
=>
Rx
(
this
);
Rx
<
T
>
get
obs
=>
Rx
<
T
>
(
this
);
}
...
...
lib/src/state/get_state.dart
View file @
6063810
...
...
@@ -5,18 +5,18 @@ import 'package:get/src/root/smart_management.dart';
import
'package:get/src/rx/rx_interface.dart'
;
class
GetxController
extends
DisposableInterface
{
final
HashSet
<
Updater
>
_updaters
=
HashSet
<
Updat
er
>();
final
HashSet
<
Updater
Builder
>
_updaters
=
HashSet
<
UpdaterBuild
er
>();
/// Update GetBuilder with update();
void
update
([
List
<
String
>
ids
,
bool
condition
=
true
])
{
if
(!
condition
)
return
;
(
ids
==
null
)
?
_updaters
.
forEach
((
rs
)
{
rs
.
updater
(()
{});
rs
()
.
updater
(()
{});
})
:
_updaters
.
where
((
element
)
=>
ids
.
contains
(
element
.
id
))
.
forEach
((
rs
)
=>
rs
.
updater
(()
{}));
.
where
((
element
)
=>
ids
.
contains
(
element
().
id
))
.
forEach
((
rs
)
=>
rs
().
updater
(()
{}));
}
@override
...
...
@@ -60,7 +60,7 @@ class GetBuilder<T extends GetxController> extends StatefulWidget {
class
_GetBuilderState
<
T
extends
GetxController
>
extends
State
<
GetBuilder
<
T
>>
{
T
controller
;
Updater
real
;
Updater
Builder
real
;
bool
isCreator
=
false
;
@override
void
initState
()
{
...
...
@@ -75,24 +75,24 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> {
isCreator
=
true
;
}
controller
=
GetInstance
().
find
<
T
>(
tag:
widget
.
tag
);
real
=
Updater
(
updater:
setState
,
id:
widget
.
id
);
real
=
()
=>
Updater
(
updater:
setState
,
id:
widget
.
id
);
controller
.
_updaters
.
add
(
real
);
}
else
if
(
isRegistred
)
{
controller
=
GetInstance
().
find
<
T
>(
tag:
widget
.
tag
);
isCreator
=
false
;
real
=
Updater
(
updater:
setState
,
id:
widget
.
id
);
real
=
()
=>
Updater
(
updater:
setState
,
id:
widget
.
id
);
controller
.
_updaters
.
add
(
real
);
}
else
{
controller
=
widget
.
init
;
isCreator
=
true
;
real
=
Updater
(
updater:
setState
,
id:
widget
.
id
);
real
=
()
=>
Updater
(
updater:
setState
,
id:
widget
.
id
);
controller
.
_updaters
.
add
(
real
);
GetInstance
().
put
<
T
>(
controller
,
tag:
widget
.
tag
);
}
}
else
{
controller
=
widget
.
init
;
isCreator
=
true
;
real
=
Updater
(
updater:
setState
,
id:
widget
.
id
);
real
=
()
=>
Updater
(
updater:
setState
,
id:
widget
.
id
);
controller
.
_updaters
.
add
(
real
);
controller
?.
onStart
();
}
...
...
@@ -141,3 +141,5 @@ class Updater {
final
String
id
;
const
Updater
({
this
.
updater
,
this
.
id
});
}
typedef
UpdaterBuilder
=
Updater
Function
();
...
...
pubspec.yaml
View file @
6063810
name
:
get
description
:
Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
version
:
3.
1.4
version
:
3.
2.0
homepage
:
https://github.com/jonataslaw/get
environment
:
...
...
Please
register
or
login
to post a comment