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
2020-10-17 08:15:49 -0500
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
65adbed3caf01af98fb2db2aa5d110d73cb91f07
65adbed3
1 parent
1066eb9f
onDelete moved into GetLifeCycle
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
39 deletions
lib/get_instance/src/lifecycle.dart
lib/get_state_manager/src/rx_flutter/rx_disposable.dart
lib/get_state_manager/src/rx_flutter/rx_notifier.dart
test/instance/get_instance_test.dart
lib/get_instance/src/lifecycle.dart
View file @
65adbed
import
'package:flutter/material.dart'
;
/// Special callable class to keep the contract of a regular method, and avoid
/// overrides if you extend the class that uses it, as Dart has no final
/// methods.
...
...
@@ -6,23 +8,35 @@
class
_InternalFinalCallback
<
T
>
{
T
Function
()
callback
;
_InternalFinalCallback
();
_InternalFinalCallback
(
{
this
.
callback
}
);
T
call
()
=>
callback
.
call
();
}
mixin
GetLifeCycle
{
class
_InternalFinalPrivateCallback
<
T
>
{
T
Function
()
_callback
;
_InternalFinalPrivateCallback
();
T
call
()
=>
_callback
.
call
();
}
mixin
GetLifeCycle
{
/// Called at the exact moment the widget is allocated in memory.
/// It uses an internal "callable" type, to avoid any @overrides in subclases.
/// This method should be internal and is required to define the
/// lifetime cycle of the subclass.
final
onStart
=
_InternalFinalCallback
<
void
>();
final
onDelete
=
_InternalFinalCallback
<
void
>();
/// Internal callback that starts the cycle of this controller.
final
onDelete
=
_InternalFinalPrivateCallback
<
void
>();
/// Called immediately after the widget is allocated in memory.
/// You might use this to initialize something for the controller.
void
onInit
()
{}
@mustCallSuper
void
onInit
()
{
onDelete
.
_callback
=
_onDelete
;
}
/// Called 1 frame after onInit(). It is the perfect place to enter
/// navigation events, like snackbar, dialogs, or a new route, or
...
...
@@ -36,6 +50,18 @@ mixin GetLifeCycle {
/// like TextEditingControllers, AnimationControllers.
/// Might be useful as well to persist some data on disk.
void
onClose
()
{}
bool
_isClosed
=
false
;
/// Checks whether the controller has already been closed.
bool
get
isClosed
=>
_isClosed
;
// Internal callback that starts the cycle of this controller.
void
_onDelete
()
{
if
(
_isClosed
)
return
;
_isClosed
=
true
;
onClose
();
}
}
/// Allow track difference between GetxServices and GetxControllers
...
...
lib/get_state_manager/src/rx_flutter/rx_disposable.dart
View file @
65adbed
import
'package:flutter/material.dart'
;
import
'package:flutter/scheduler.dart'
;
import
'../../../get_instance/src/lifecycle.dart'
;
...
...
@@ -15,14 +16,8 @@ abstract class DisposableInterface with GetLifeCycle {
/// Checks whether the controller has already been initialized.
bool
get
initialized
=>
_initialized
;
bool
_isClosed
=
false
;
/// Checks whether the controller has already been closed.
bool
get
isClosed
=>
_isClosed
;
DisposableInterface
()
{
onStart
.
callback
=
_onStart
;
onDelete
.
callback
=
_onDelete
;
}
// Internal callback that starts the cycle of this controller.
...
...
@@ -33,22 +28,17 @@ abstract class DisposableInterface with GetLifeCycle {
SchedulerBinding
.
instance
?.
addPostFrameCallback
((
_
)
=>
onReady
());
}
// Internal callback that starts the cycle of this controller.
void
_onDelete
()
{
if
(
_isClosed
)
return
;
_isClosed
=
true
;
onClose
();
}
/// Called immediately after the widget is allocated in memory.
/// You might use this to initialize something for the controller.
@override
void
onInit
()
{}
@mustCallSuper
void
onInit
()
=>
super
.
onInit
();
/// Called 1 frame after onInit(). It is the perfect place to enter
/// navigation events, like snackbar, dialogs, or a new route, or
/// async request.
@override
@mustCallSuper
void
onReady
()
{}
/// Called before [onDelete] method. [onClose] might be used to
...
...
@@ -58,5 +48,6 @@ abstract class DisposableInterface with GetLifeCycle {
/// like TextEditingControllers, AnimationControllers.
/// Might be useful as well to persist some data on disk.
@override
@mustCallSuper
void
onClose
()
{}
}
...
...
lib/get_state_manager/src/rx_flutter/rx_notifier.dart
View file @
65adbed
...
...
@@ -39,7 +39,6 @@ typedef Condition = bool Function();
abstract
class
GetNotifier
<
T
>
extends
Value
<
T
>
with
GetLifeCycle
{
GetNotifier
(
T
initial
)
:
super
(
initial
)
{
onStart
.
callback
=
_onStart
;
onDelete
.
callback
=
_onDelete
;
_fillEmptyStatus
();
}
...
...
@@ -48,11 +47,6 @@ abstract class GetNotifier<T> extends Value<T> with GetLifeCycle {
/// Checks whether the controller has already been initialized.
bool
get
initialized
=>
_initialized
;
bool
_isClosed
=
false
;
/// Checks whether the controller has already been closed.
bool
get
isClosed
=>
_isClosed
;
// Internal callback that starts the cycle of this controller.
void
_onStart
()
{
if
(
_initialized
)
return
;
...
...
@@ -61,13 +55,6 @@ abstract class GetNotifier<T> extends Value<T> with GetLifeCycle {
SchedulerBinding
.
instance
?.
addPostFrameCallback
((
_
)
=>
onReady
());
}
// Internal callback that starts the cycle of this controller.
void
_onDelete
()
{
if
(
_isClosed
)
return
;
_isClosed
=
true
;
onClose
();
}
RxStatus
_status
;
bool
get
isNullOrEmpty
{
...
...
test/instance/get_instance_test.dart
View file @
65adbed
...
...
@@ -12,7 +12,6 @@ class Mock {
class
DisposableController
with
GetLifeCycle
{
DisposableController
()
{
onStart
.
callback
=
_onStart
;
onDelete
.
callback
=
_onDelete
;
}
// Internal callback that starts the cycle of this controller.
...
...
@@ -21,18 +20,13 @@ class DisposableController with GetLifeCycle {
onInit
();
}
// Internal callback that starts the cycle of this controller.
void
_onDelete
()
{
if
(
isClosed
)
return
;
isClosed
=
true
;
onClose
();
}
bool
initialized
=
false
;
bool
isClosed
=
false
;
@override
void
onInit
()
async
{
super
.
onInit
();
initialized
=
true
;
}
}
...
...
Please
register
or
login
to post a comment