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
Frank Moreno
2021-06-13 22:54:58 -0500
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ff2d7b31e2ad6a66045e99abfb2c70eb3fe064b7
ff2d7b31
1 parent
b9d377cd
refactoring using RxInterface.notifyChildren
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
51 deletions
lib/get_state_manager/src/rx_flutter/rx_getx_widget.dart
lib/get_state_manager/src/rx_flutter/rx_obx_widget.dart
lib/get_state_manager/src/rx_flutter/rx_getx_widget.dart
View file @
ff2d7b3
...
...
@@ -45,10 +45,7 @@ class GetX<T extends DisposableInterface> extends StatefulWidget {
}
class
GetXState
<
T
extends
DisposableInterface
>
extends
State
<
GetX
<
T
>>
{
GetXState
()
{
_observer
=
RxNotifier
();
}
RxInterface
?
_observer
;
final
_observer
=
RxNotifier
();
T
?
controller
;
bool
?
_isCreator
=
false
;
late
StreamSubscription
_subs
;
...
...
@@ -80,7 +77,7 @@ class GetXState<T extends DisposableInterface> extends State<GetX<T>> {
if
(
widget
.
global
&&
Get
.
smartManagement
==
SmartManagement
.
onlyBuilder
)
{
controller
?.
onStart
();
}
_subs
=
_observer
!
.
listen
((
data
)
=>
setState
(()
{}),
cancelOnError:
false
);
_subs
=
_observer
.
listen
((
data
)
=>
setState
(()
{}),
cancelOnError:
false
);
super
.
initState
();
}
...
...
@@ -107,30 +104,15 @@ class GetXState<T extends DisposableInterface> extends State<GetX<T>> {
}
}
_subs
.
cancel
();
_observer
!
.
close
();
_observer
.
close
();
controller
=
null
;
_isCreator
=
null
;
super
.
dispose
();
}
Widget
get
notifyChildren
{
final
observer
=
RxInterface
.
proxy
;
RxInterface
.
proxy
=
_observer
;
final
result
=
widget
.
builder
(
controller
!);
if
(!
_observer
!.
canUpdate
)
{
throw
"""
[Get] the improper use of a GetX has been detected.
You should only use GetX or Obx for the specific widget that will be updated.
If you are seeing this error, you probably did not insert any observable variables into GetX/Obx
or insert them outside the scope that GetX considers suitable for an update
(example: GetX => HeavyWidget => variableObservable).
If you need to update a parent widget and a child widget, wrap each one in an Obx/GetX.
"""
;
}
RxInterface
.
proxy
=
observer
;
return
result
;
}
@override
Widget
build
(
BuildContext
context
)
=>
notifyChildren
;
Widget
build
(
BuildContext
context
)
=>
RxInterface
.
notifyChildren
(
_observer
,
()
=>
widget
.
builder
(
controller
!),
);
}
...
...
lib/get_state_manager/src/rx_flutter/rx_obx_widget.dart
View file @
ff2d7b3
...
...
@@ -20,17 +20,13 @@ abstract class ObxWidget extends StatefulWidget {
}
class
_ObxState
extends
State
<
ObxWidget
>
{
RxInterface
?
_observer
;
final
_observer
=
RxNotifier
()
;
late
StreamSubscription
subs
;
_ObxState
()
{
_observer
=
RxNotifier
();
}
@override
void
initState
()
{
subs
=
_observer
!.
listen
(
_updateTree
,
cancelOnError:
false
);
super
.
initState
();
subs
=
_observer
.
listen
(
_updateTree
,
cancelOnError:
false
);
}
void
_updateTree
(
_
)
{
...
...
@@ -42,30 +38,13 @@ class _ObxState extends State<ObxWidget> {
@override
void
dispose
()
{
subs
.
cancel
();
_observer
!
.
close
();
_observer
.
close
();
super
.
dispose
();
}
Widget
get
notifyChilds
{
final
observer
=
RxInterface
.
proxy
;
RxInterface
.
proxy
=
_observer
;
final
result
=
widget
.
build
();
if
(!
_observer
!.
canUpdate
)
{
throw
"""
[Get] the improper use of a GetX has been detected.
You should only use GetX or Obx for the specific widget that will be updated.
If you are seeing this error, you probably did not insert any observable variables into GetX/Obx
or insert them outside the scope that GetX considers suitable for an update
(example: GetX => HeavyWidget => variableObservable).
If you need to update a parent widget and a child widget, wrap each one in an Obx/GetX.
"""
;
}
RxInterface
.
proxy
=
observer
;
return
result
;
}
@override
Widget
build
(
BuildContext
context
)
=>
notifyChilds
;
Widget
build
(
BuildContext
context
)
=>
RxInterface
.
notifyChildren
(
_observer
,
widget
.
build
);
}
/// The simplest reactive widget in GetX.
...
...
Please
register
or
login
to post a comment