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-10-25 16:41:01 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
afc6f75bf0ef9ce37201a17b00e2a63fd0197cc2
afc6f75b
1 parent
7146b6a5
change value property to be protected
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
11 deletions
example/lib/pages/home/presentation/controllers/home_controller.dart
example/lib/pages/home/presentation/views/country_view.dart
example/lib/pages/home/presentation/views/home_view.dart
example/test/main_test.dart
lib/get_state_manager/src/rx_flutter/rx_notifier.dart
example/lib/pages/home/presentation/controllers/home_controller.dart
View file @
afc6f75
...
...
@@ -3,7 +3,7 @@ import 'package:get/get.dart';
import
'../../domain/adapters/repository_adapter.dart'
;
import
'../../domain/entity/cases_model.dart'
;
class
HomeController
extends
GetxController
with
Stat
us
Mixin
<
CasesModel
>
{
class
HomeController
extends
GetxController
with
Stat
e
Mixin
<
CasesModel
>
{
HomeController
({
this
.
homeRepository
});
/// inject repo abstraction dependency
...
...
example/lib/pages/home/presentation/views/country_view.dart
View file @
afc6f75
...
...
@@ -29,9 +29,9 @@ class CountryView extends GetView<HomeController> {
),
body:
Center
(
child:
ListView
.
builder
(
itemCount:
controller
.
valu
e
.
countries
.
length
,
itemCount:
controller
.
stat
e
.
countries
.
length
,
itemBuilder:
(
context
,
index
)
{
final
country
=
controller
.
valu
e
.
countries
[
index
];
final
country
=
controller
.
stat
e
.
countries
[
index
];
return
ListTile
(
onTap:
()
{
Get
.
toNamed
(
'/details'
,
arguments:
country
);
...
...
example/lib/pages/home/presentation/views/home_view.dart
View file @
afc6f75
...
...
@@ -27,7 +27,7 @@ class HomeView extends GetView<HomeController> {
centerTitle:
true
,
),
body:
Center
(
child:
controller
(
child:
controller
.
obx
(
(
state
)
{
return
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
...
...
example/test/main_test.dart
View file @
afc6f75
...
...
@@ -65,12 +65,12 @@ void main() {
await
Future
.
delayed
(
Duration
(
milliseconds:
100
));
if
(
controller
.
status
.
isError
)
{
expect
(
controller
.
valu
e
,
null
);
expect
(
controller
.
stat
e
,
null
);
}
if
(
controller
.
status
.
isSuccess
)
{
expect
(
controller
.
value
.
global
.
totalDeaths
,
100
);
expect
(
controller
.
value
.
global
.
totalConfirmed
,
200
);
expect
(
controller
.
state
.
global
.
totalDeaths
,
100
);
expect
(
controller
.
state
.
global
.
totalConfirmed
,
200
);
}
});
...
...
lib/get_state_manager/src/rx_flutter/rx_notifier.dart
View file @
afc6f75
...
...
@@ -5,7 +5,7 @@ import '../../../instance_manager.dart';
import
'../../get_state_manager.dart'
;
import
'../simple/list_notifier.dart'
;
mixin
Stat
us
Mixin
<
T
>
on
ListNotifier
{
mixin
Stat
e
Mixin
<
T
>
on
ListNotifier
{
T
_value
;
RxStatus
_status
;
...
...
@@ -31,11 +31,15 @@ mixin StatusMixin<T> on ListNotifier {
return
_status
??=
_status
=
RxStatus
.
loading
();
}
T
get
state
=>
value
;
@protected
T
get
value
{
notifyChildrens
();
return
_value
;
}
@protected
set
value
(
T
newValue
)
{
if
(
_value
==
newValue
)
return
;
_value
=
newValue
;
...
...
@@ -60,13 +64,33 @@ mixin StatusMixin<T> on ListNotifier {
}
class
Value
<
T
>
extends
ListNotifier
with
Stat
us
Mixin
<
T
>
with
Stat
e
Mixin
<
T
>
implements
ValueListenable
<
T
>
{
Value
(
T
val
)
{
_value
=
val
;
_fillEmptyStatus
();
}
@override
T
get
value
{
notifyChildrens
();
return
_value
;
}
@override
set
value
(
T
newValue
)
{
if
(
_value
==
newValue
)
return
;
_value
=
newValue
;
refresh
();
}
T
call
([
T
v
])
{
if
(
v
!=
null
)
{
value
=
v
;
}
return
value
;
}
void
update
(
void
fn
(
T
value
))
{
fn
(
value
);
refresh
();
...
...
@@ -97,8 +121,8 @@ abstract class GetNotifier<T> extends Value<T> with GetLifeCycleBase {
}
}
extension
StateExt
<
T
>
on
StatusMixin
<
T
>
{
Widget
call
(
NotifierBuilder
<
T
>
widget
,
{
Widget
onError
,
Widget
onLoading
})
{
extension
StateExt
<
T
>
on
StateMixin
<
T
>
{
Widget
obx
(
NotifierBuilder
<
T
>
widget
,
{
Widget
onError
,
Widget
onLoading
})
{
assert
(
widget
!=
null
);
return
SimpleBuilder
(
builder:
(
_
)
{
if
(
status
.
isLoading
)
{
...
...
Please
register
or
login
to post a comment