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 Borges
2021-03-02 20:28:51 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4141e29095a5334df1054b49bb3b7bfaef1badc3
4141e290
1 parent
8ee2325b
add ScrollMixin and isLoadingMore to controller status
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
29 deletions
lib/get_state_manager/src/rx_flutter/rx_notifier.dart
lib/get_state_manager/src/simple/get_controllers.dart
lib/get_state_manager/src/rx_flutter/rx_notifier.dart
View file @
4141e29
...
...
@@ -152,51 +152,36 @@ class RxStatus {
final
bool
isError
;
final
bool
isSuccess
;
final
bool
isEmpty
;
final
bool
isLoadingMore
;
final
String
errorMessage
;
RxStatus
.
_
({
this
.
isEmpty
,
this
.
isLoading
,
this
.
isError
,
this
.
isSuccess
,
this
.
isEmpty
=
false
,
this
.
isLoading
=
false
,
this
.
isError
=
false
,
this
.
isSuccess
=
false
,
this
.
errorMessage
,
this
.
isLoadingMore
=
false
,
});
factory
RxStatus
.
loading
()
{
return
RxStatus
.
_
(
isLoading:
true
,
isError:
false
,
isSuccess:
false
,
isEmpty:
false
,
);
return
RxStatus
.
_
(
isLoading:
true
);
}
factory
RxStatus
.
loadingMore
()
{
return
RxStatus
.
_
(
isSuccess:
true
,
isLoadingMore:
true
);
}
factory
RxStatus
.
success
()
{
return
RxStatus
.
_
(
isLoading:
false
,
isError:
false
,
isSuccess:
true
,
isEmpty:
false
,
);
return
RxStatus
.
_
(
isSuccess:
true
);
}
factory
RxStatus
.
error
([
String
message
])
{
return
RxStatus
.
_
(
isLoading:
false
,
isError:
true
,
isSuccess:
false
,
isEmpty:
false
,
errorMessage:
message
,
);
return
RxStatus
.
_
(
isError:
true
,
errorMessage:
message
);
}
factory
RxStatus
.
empty
()
{
return
RxStatus
.
_
(
isLoading:
false
,
isError:
false
,
isSuccess:
false
,
isEmpty:
true
,
);
return
RxStatus
.
_
(
isEmpty:
true
);
}
}
...
...
lib/get_state_manager/src/simple/get_controllers.dart
View file @
4141e29
// ignore: prefer_mixin
import
'package:flutter/widgets.dart'
;
import
'../../../instance_manager.dart'
;
import
'../rx_flutter/rx_disposable.dart'
;
import
'../rx_flutter/rx_notifier.dart'
;
...
...
@@ -26,6 +27,50 @@ abstract class GetxController extends DisposableInterface with ListNotifier {
}
}
mixin
ScrollMixin
on
GetLifeCycleBase
{
final
ScrollController
scroll
=
ScrollController
();
@override
void
onInit
()
{
super
.
onInit
();
scroll
.
addListener
(
_listener
);
}
bool
_canFetchBottom
=
true
;
bool
_canFetchTop
=
true
;
void
_listener
()
{
if
(
scroll
.
position
.
atEdge
)
{
_checkIfCanLoadMore
();
}
}
Future
<
void
>
_checkIfCanLoadMore
()
async
{
if
(
scroll
.
position
.
pixels
==
0
)
{
if
(!
_canFetchTop
)
return
;
_canFetchTop
=
false
;
await
onTopScroll
();
_canFetchTop
=
true
;
}
else
{
if
(!
_canFetchBottom
)
return
;
_canFetchBottom
=
false
;
await
onEndScroll
();
_canFetchBottom
=
true
;
}
}
Future
<
void
>
onEndScroll
();
Future
<
void
>
onTopScroll
();
@override
void
onClose
()
{
scroll
.
removeListener
(
_listener
);
super
.
onClose
();
}
}
abstract
class
RxController
extends
DisposableInterface
{}
abstract
class
SuperController
<
T
>
extends
FullLifeCycleController
...
...
Please
register
or
login
to post a comment