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-18 01:49:40 -0300
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
6048106c450e761f3b3ec90fa481f8d9834a8a7f
6048106c
2 parents
528a34a1
b20f342a
update tests structures
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
82 additions
and
90 deletions
.github/workflows/main.yml
example/lib/pages/home/presentation/controllers/home_controller.dart
example/test/main_test.dart
lib/get_core/get_core.dart
lib/get_core/src/typedefs.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
pubspec.yaml
test/instance/get_instance_test.dart
test/utils/extensions/dynamic_extensions_test.dart
.github/workflows/main.yml
View file @
6048106
#The name of your workflow.
name
:
build
name
:
build
# Trigger the workflow on push or pull request
on
:
push
:
branches
:
[
master
]
branches
:
[
master
]
pull_request
:
branches
:
[
master
]
branches
:
[
master
]
#A workflow run is made up of one or more jobs. Jobs run in parallel by default.
jobs
:
test
:
#The type of machine to run the job on. [windows,macos, ubuntu , self-hosted]
defaults
:
...
...
@@ -24,8 +23,8 @@ jobs:
# https://github.com/marketplace/actions/flutter-action
-
uses
:
subosito/flutter-action@v1
with
:
flutter-version
:
'
1.20.4'
channel
:
'
stable'
flutter-version
:
"
1.22.2"
channel
:
"
stable"
-
run
:
flutter pub get
#- run: flutter analyze
# run flutter widgets tests and unit tests
...
...
@@ -33,4 +32,3 @@ jobs:
# Upload coverage reports to Codecov
# https://github.com/marketplace/actions/codecov
-
uses
:
codecov/codecov-action@v1.0.7
...
...
example/lib/pages/home/presentation/controllers/home_controller.dart
View file @
6048106
...
...
@@ -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
{
...
...
example/test/main_test.dart
View file @
6048106
...
...
@@ -170,7 +170,9 @@ class Controller extends GetxController {
super
.
onReady
();
}
@override
void
onClose
()
{
super
.
onClose
();
print
(
'onClose'
);
}
}
...
...
lib/get_core/get_core.dart
View file @
6048106
...
...
@@ -5,3 +5,5 @@ export 'src/get_main.dart';
export
'src/log.dart'
;
export
'src/smart_management.dart'
;
export
'src/typedefs.dart'
;
...
...
lib/get_core/src/typedefs.dart
0 → 100644
View file @
6048106
typedef
ValueUpdater
<
T
>
=
T
Function
();
...
...
lib/get_instance/src/lifecycle.dart
View file @
6048106
import
'package:meta/meta.dart'
;
import
'../../get_core/get_core.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.
/// Used in [DisposableInterface] to avoid the danger of overriding onStart.
///
class
_InternalFinalCallback
<
T
>
{
T
Function
()
callback
;
ValueUpdater
<
T
>
_
callback
;
_InternalFinalCallback
(
)
;
_InternalFinalCallback
(
{
ValueUpdater
<
T
>
callback
})
:
_callback
=
callback
;
T
call
()
=>
callback
.
call
();
T
call
()
=>
_
callback
.
call
();
}
mixin
GetLifeCycle
{
/// 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
/// lifetime cycle of the subclass.
final
onStart
=
_InternalFinalCallback
<
void
>();
/// Internal callback that starts the cycle of this controller.
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
()
{}
/// Called 1 frame after onInit(). It is the perfect place to enter
/// navigation events, like snackbar, dialogs, or a new route, or
/// async request.
@mustCallSuper
void
onReady
()
{}
/// Called before [onDelete] method. [onClose] might be used to
...
...
@@ -35,7 +57,32 @@ mixin GetLifeCycle {
/// Or dispose objects that can potentially create some memory leaks,
/// like TextEditingControllers, AnimationControllers.
/// Might be useful as well to persist some data on disk.
@mustCallSuper
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.
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 @
6048106
import
'package:flutter/material.dart'
;
import
'package:flutter/scheduler.dart'
;
import
'../../../get_instance/src/lifecycle.dart'
;
...
...
@@ -10,45 +11,24 @@ 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
;
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.
void
_onStart
()
{
if
(
_initialized
)
return
;
onInit
();
_initialized
=
true
;
SchedulerBinding
.
instance
?.
addPostFrameCallback
((
_
)
=>
onReady
());
}
// Internal callback that starts the cycle of this controller.
void
_onDelete
()
{
if
(
_isClosed
)
return
;
_isClosed
=
true
;
onClose
();
initLifeCycle
();
}
/// 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
();
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
/// async request.
@override
@mustCallSuper
void
onReady
()
{}
/// Called before [onDelete] method. [onClose] might be used to
...
...
lib/get_state_manager/src/rx_flutter/rx_notifier.dart
View file @
6048106
...
...
@@ -38,36 +38,17 @@ typedef Condition = bool Function();
abstract
class
GetNotifier
<
T
>
extends
Value
<
T
>
with
GetLifeCycle
{
GetNotifier
(
T
initial
)
:
super
(
initial
)
{
onStart
.
callback
=
_onStart
;
onDelete
.
callback
=
_onDelete
;
initLifeCycle
();
_fillEmptyStatus
();
}
bool
_initialized
=
false
;
/// 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
;
onInit
();
_initialized
=
true
;
@override
@mustCallSuper
void
onInit
()
{
super
.
onInit
();
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
{
...
...
pubspec.yaml
View file @
6048106
...
...
@@ -4,11 +4,12 @@ version: 3.13.2
homepage
:
https://github.com/jonataslaw/getx
environment
:
sdk
:
"
>=2.
8
.0
<3.0.0"
sdk
:
"
>=2.
10
.0
<3.0.0"
dependencies
:
flutter
:
sdk
:
flutter
meta
:
1.3.0-nullsafety.3
dev_dependencies
:
flutter_test
:
...
...
test/instance/get_instance_test.dart
View file @
6048106
...
...
@@ -11,29 +11,7 @@ class Mock {
class
DisposableController
with
GetLifeCycle
{
DisposableController
()
{
onStart
.
callback
=
_onStart
;
onDelete
.
callback
=
_onDelete
;
}
// Internal callback that starts the cycle of this controller.
void
_onStart
()
{
if
(
initialized
)
return
;
onInit
();
}
// Internal callback that starts the cycle of this controller.
void
_onDelete
()
{
if
(
isClosed
)
return
;
isClosed
=
true
;
onClose
();
}
bool
initialized
=
false
;
bool
isClosed
=
false
;
void
onInit
()
async
{
initialized
=
true
;
initLifeCycle
();
}
}
...
...
test/utils/extensions/dynamic_extensions_test.dart
View file @
6048106
...
...
@@ -73,7 +73,6 @@ void main() {
var
expected
=
''
;
void
logFunction
(
String
prefix
,
dynamic
value
,
String
info
,
{
bool
isError
=
false
})
{
print
(
'algo'
);
expected
=
'
$prefix
$value
$info
'
.
trim
();
}
...
...
Please
register
or
login
to post a comment