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-02 13:47:33 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
56ea141f3ad7b0e9fa781cfa4046a0c108767373
56ea141f
1 parent
9786b840
Added status
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
2 deletions
packages/get_rx/lib/src/rx_core/rx_impl.dart
packages/get_rx/lib/src/rx_core/rx_impl.dart
View file @
56ea141
...
...
@@ -229,9 +229,41 @@ class Rx<T> extends _RxImpl<T> {
dynamic
toJson
()
=>
(
value
as
dynamic
)?.
toJson
();
}
enum
RxStatus
{
loading
,
error
,
success
}
/// It's Experimental class, the Api can be change
abstract
class
RxState
<
T
>
extends
_RxImpl
<
T
>
{
RxState
(
T
initial
)
:
super
(
initial
);
RxState
(
T
initial
)
:
super
(
initial
)
{
_fillEmptyStatus
();
}
RxStatus
_status
;
bool
get
isNullOrEmpty
{
if
(
_value
==
null
)
return
true
;
dynamic
val
=
_value
;
var
result
=
false
;
if
(
val
is
Iterable
)
{
result
=
val
.
isEmpty
;
}
else
if
(
val
is
String
)
{
result
=
val
.
isEmpty
;
}
else
if
(
val
is
Map
)
{
result
=
val
.
isEmpty
;
}
return
result
;
}
void
_fillEmptyStatus
()
{
_status
=
isNullOrEmpty
?
RxStatus
.
loading
:
RxStatus
.
success
;
}
RxStatus
get
status
{
return
_status
;
}
bool
get
isLoading
=>
_status
==
RxStatus
.
loading
;
bool
get
hasError
=>
_status
==
RxStatus
.
error
;
bool
get
hasData
=>
_status
==
RxStatus
.
success
;
@protected
void
refresh
()
{
...
...
@@ -259,7 +291,10 @@ abstract class RxState<T> extends _RxImpl<T> {
}
@protected
void
change
(
T
newState
)
{
void
change
(
T
newState
,
{
RxStatus
status
})
{
if
(
status
!=
null
)
{
_status
=
status
;
}
if
(
newState
!=
_value
)
{
value
=
newState
;
}
...
...
Please
register
or
login
to post a comment