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 09:11:48 -0500
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
00271c358afbd3afa5337aa3084a301754dfc092
00271c35
1 parent
523a96ec
life cycle control logic only dependends on GetLifeCycle and not in the implementations
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
43 deletions
example/lib/pages/home/presentation/controllers/home_controller.dart
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
example/lib/pages/home/presentation/controllers/home_controller.dart
View file @
00271c3
...
...
@@ -19,7 +19,10 @@ class HomeController extends GetxController {
/// When the controller is initialized, make the http request
@override
void
onInit
()
=>
fetchDataFromApi
();
void
onInit
()
{
super
.
onInit
();
fetchDataFromApi
();
}
/// fetch cases from Api
Future
<
void
>
fetchDataFromApi
()
async
{
...
...
lib/get_instance/src/lifecycle.dart
View file @
00271c3
...
...
@@ -4,24 +4,32 @@ import 'package:flutter/material.dart';
/// overrides if you extend the class that uses it, as Dart has no final
/// methods.
/// Used in [DisposableInterface] to avoid the danger of overriding onStart.
///
class
_InternalFinalCallback
<
T
>
{
T
Function
()
callback
;
_InternalFinalCallback
({
this
.
callback
});
T
call
()
=>
callback
.
call
();
}
ValueGetter
<
T
>
_callback
;
class
_InternalFinalPrivateCallback
<
T
>
{
T
Function
()
_callback
;
_InternalFinalPrivateCallback
();
_InternalFinalCallback
({
ValueGetter
<
T
>
callback
})
:
_callback
=
callback
;
T
call
()
=>
_callback
.
call
();
}
/// The [GetLifeCycle]
///
/// ```dart
/// class SomeController with GetLifeCycle {
/// SomeController() {
/// initLifeCycle();
/// }
/// }
/// ```
mixin
GetLifeCycle
{
/// The `initLifeCycle` works as a constructor for the [GetLifeCycle]
///
/// This method must be invoked in the constructor of the implementation
void
initLifeCycle
()
{
onStart
.
_callback
=
_onStart
;
onDelete
.
_callback
=
_onDelete
;
}
/// 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
...
...
@@ -29,14 +37,12 @@ mixin GetLifeCycle {
final
onStart
=
_InternalFinalCallback
<
void
>();
/// Internal callback that starts the cycle of this controller.
final
onDelete
=
_InternalFinal
Private
Callback
<
void
>();
final
onDelete
=
_InternalFinalCallback
<
void
>();
/// Called immediately after the widget is allocated in memory.
/// You might use this to initialize something for the controller.
@mustCallSuper
void
onInit
()
{
onDelete
.
_callback
=
_onDelete
;
}
void
onInit
()
{}
/// Called 1 frame after onInit(). It is the perfect place to enter
/// navigation events, like snackbar, dialogs, or a new route, or
...
...
@@ -51,6 +57,18 @@ mixin GetLifeCycle {
/// Might be useful as well to persist some data on disk.
void
onClose
()
{}
bool
_initialized
=
false
;
/// Checks whether the controller has already been initialized.
bool
get
initialized
=>
_initialized
;
// Internal callback that starts the cycle of this controller.
void
_onStart
()
{
if
(
_initialized
)
return
;
onInit
();
_initialized
=
true
;
}
bool
_isClosed
=
false
;
/// Checks whether the controller has already been closed.
...
...
lib/get_state_manager/src/rx_flutter/rx_disposable.dart
View file @
00271c3
...
...
@@ -11,28 +11,18 @@ import '../../../get_instance/src/lifecycle.dart';
abstract
class
GetxService
extends
DisposableInterface
with
GetxServiceMixin
{}
abstract
class
DisposableInterface
with
GetLifeCycle
{
bool
_initialized
=
false
;
/// Checks whether the controller has already been initialized.
bool
get
initialized
=>
_initialized
;
DisposableInterface
()
{
onStart
.
callback
=
_onStart
;
}
// Internal callback that starts the cycle of this controller.
void
_onStart
()
{
if
(
_initialized
)
return
;
onInit
();
_initialized
=
true
;
SchedulerBinding
.
instance
?.
addPostFrameCallback
((
_
)
=>
onReady
());
initLifeCycle
();
}
/// Called immediately after the widget is allocated in memory.
/// You might use this to initialize something for the controller.
@override
@mustCallSuper
void
onInit
()
=>
super
.
onInit
();
void
onInit
()
{
super
.
onInit
();
SchedulerBinding
.
instance
?.
addPostFrameCallback
((
_
)
=>
onReady
());
}
/// Called 1 frame after onInit(). It is the perfect place to enter
/// navigation events, like snackbar, dialogs, or a new route, or
...
...
@@ -48,6 +38,5 @@ 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 @
00271c3
...
...
@@ -38,20 +38,14 @@ typedef Condition = bool Function();
abstract
class
GetNotifier
<
T
>
extends
Value
<
T
>
with
GetLifeCycle
{
GetNotifier
(
T
initial
)
:
super
(
initial
)
{
onStart
.
callback
=
_onStart
;
initLifeCycle
()
;
_fillEmptyStatus
();
}
bool
_initialized
=
false
;
/// Checks whether the controller has already been initialized.
bool
get
initialized
=>
_initialized
;
// Internal callback that starts the cycle of this controller.
void
_onStart
()
{
if
(
_initialized
)
return
;
onInit
();
_initialized
=
true
;
@override
@mustCallSuper
void
onInit
()
{
super
.
onInit
();
SchedulerBinding
.
instance
?.
addPostFrameCallback
((
_
)
=>
onReady
());
}
...
...
Please
register
or
login
to post a comment