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
Jonny Borges
2021-12-31 12:37:44 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a39e9a74fb8cfbd96a8e4fd3cc542df2b242667d
a39e9a74
1 parent
65409d41
add Binding retrocompatibility
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
167 additions
and
168 deletions
example/lib/main.dart
lib/get_instance/src/bindings_interface.dart
lib/get_navigation/src/extension_navigation.dart
lib/get_navigation/src/root/get_cupertino_app.dart
lib/get_navigation/src/root/get_material_app.dart
lib/get_navigation/src/routes/default_route.dart
lib/get_navigation/src/routes/get_route.dart
lib/get_navigation/src/routes/route_middleware.dart
lib/get_rx/src/rx_stream/rx_stream.dart
lib/get_rx/src/rx_types/rx_core/rx_impl.dart
lib/get_rx/src/rx_types/rx_types.dart
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/simple/get_state.dart
lib/get_state_manager/src/simple/list_notifier.dart
example/lib/main.dart
View file @
a39e9a7
import
'package:flutter/material.dart'
;
import
'package:get/get.dart'
;
import
'lang/translation_service.dart'
;
import
'routes/app_pages.dart'
;
import
'shared/logger/logger_utils.dart'
;
void
main
(
)
{
//MyBindings().dependencies();
runApp
(
Binds
(
binds:
[
Bind
.
lazyPut
(()
=>
Controller
()),
Bind
.
lazyPut
(()
=>
Controller2
()),
],
child:
GetMaterialApp
(
home:
Home
(),
),
),
);
runApp
(
MyApp
());
}
class
MyApp
extends
StatelessWidget
{
const
MyApp
({
Key
?
key
})
:
super
(
key:
key
);
class
MyBindings
extends
Binding
{
@override
List
<
Bind
>
dependencies
()
{
return
[
Bind
.
put
(
Controller
()),
Bind
.
put
(
Controller2
()),
];
Widget
build
(
BuildContext
context
)
{
return
GetMaterialApp
.
router
(
debugShowCheckedModeBanner:
false
,
enableLog:
true
,
logWriterCallback:
Logger
.
write
,
// initialRoute: AppPages.INITIAL,
getPages:
AppPages
.
routes
,
locale:
TranslationService
.
locale
,
fallbackLocale:
TranslationService
.
fallbackLocale
,
translations:
TranslationService
(),
);
}
}
class
Controller
extends
GetxController
{
final
count
=
0
.
obs
;
void
increment
()
{
count
.
value
++;
update
();
}
}
/// Nav 2 snippet
// void main() {
// runApp(MyApp());
// }
class
Controller2
extends
GetxController
{
final
count
=
0
.
obs
;
// class MyApp extends StatelessWidget {
// MyApp({Key? key}) : super(key: key);
Controller2
();
void
increment
()
{
count
.
value
++;
update
();
}
}
// @override
// Widget build(BuildContext context) {
// return GetMaterialApp.router(
// getPages: [
// GetPage(
// participatesInRootNavigator: true,
// name: '/first',
// page: () => First()),
// GetPage(
// name: '/second',
// page: () => Second(),
// ),
// GetPage(
// name: '/third',
// page: () => Third(),
// ),
// ],
// debugShowCheckedModeBanner: false,
// );
// }
// }
class
Home
extends
ObxStatelessWidget
{
const
Home
({
Key
?
key
})
:
super
(
key:
key
);
@override
Widget
build
(
BuildContext
context
)
{
print
(
'sasasasa'
);
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
"counter"
)),
body:
Builder
(
builder:
(
context
)
{
return
Center
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
Builder
(
builder:
(
context
)
{
print
(
'builder'
);
final
controller
=
context
.
listen
<
Controller
>();
return
Text
(
'
${controller.count.value}
'
);
}),
ElevatedButton
(
child:
Text
(
'Next Route'
),
onPressed:
()
{
Get
.
to
(()
=>
Second
());
},
),
],
),
);
}),
floatingActionButton:
FloatingActionButton
(
child:
Icon
(
Icons
.
add
),
onPressed:
()
{
Get
.
find
<
Controller
>().
increment
();
},
),
);
}
}
// class First extends StatelessWidget {
// @override
// Widget build(BuildContext context) {
// return Scaffold(
// appBar: AppBar(
// title: Text('page one'),
// leading: IconButton(
// icon: Icon(Icons.more),
// onPressed: () {
// Get.changeTheme(
// context.isDarkMode ? ThemeData.light() : ThemeData.dark());
// },
// ),
// ),
// body: Center(
// child: Container(
// height: 300,
// width: 300,
// child: ElevatedButton(
// onPressed: () {},
// child: Text('next screen'),
// ),
// ),
// ),
// );
// }
// }
class
Second
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(),
floatingActionButton:
FloatingActionButton
(
onPressed:
()
{
context
.
get
<
Controller2
>().
increment
();
},
),
body:
Center
(
child:
Builder
(
builder:
(
context
)
{
final
ctrl
=
context
.
listen
<
Controller2
>();
return
Text
(
"
${ctrl.count}
"
);
}),
),
);
}
}
// class Second extends StatelessWidget {
// @override
// Widget build(BuildContext context) {
// return Scaffold(
// appBar: AppBar(
// title: Text('page two ${Get.parameters["id"]}'),
// ),
// body: Center(
// child: Container(
// height: 300,
// width: 300,
// child: ElevatedButton(
// onPressed: () {},
// child: Text('next screen'),
// ),
// ),
// ),
// );
// }
// }
// class Third extends StatelessWidget {
// @override
// Widget build(BuildContext context) {
// return Scaffold(
// backgroundColor: Colors.red,
// appBar: AppBar(
// title: Text('page three'),
// ),
// body: Center(
// child: Container(
// height: 300,
// width: 300,
// child: ElevatedButton(
// onPressed: () {},
// child: Text('go to first screen'),
// ),
// ),
// ),
// );
// }
// }
...
...
lib/get_instance/src/bindings_interface.dart
View file @
a39e9a7
// ignore: one_member_abstracts
import
'get_instance.dart'
;
// ignore: one_member_abstracts
abstract
class
BindingsInterface
<
T
>
{
T
dependencies
();
}
/// [Bindings] should be extended or implemented.
/// When using `GetMaterialApp`, all `GetPage`s and navigation
/// methods (like Get.to()) have a `binding` property that takes an
...
...
@@ -7,8 +13,9 @@ import 'get_instance.dart';
/// dependencies() (via Get.put()) for the Route you are opening.
// ignore: one_member_abstracts
@Deprecated
(
'Use Binding instead'
)
abstract
class
Bindings
<
T
>
{
T
dependencies
();
abstract
class
Bindings
extends
BindingsInterface
<
void
>
{
@override
void
dependencies
();
}
/// Simplifies Bindings generation from a single callback.
...
...
@@ -59,8 +66,4 @@ class BindingsBuilder<T> extends Bindings {
}
}
// abstract class INavigation {}
// typedef Snack = Function();
// typedef Modal = Function();
// typedef Route = Function();
typedef
BindingBuilderCallback
=
void
Function
();
...
...
lib/get_navigation/src/extension_navigation.dart
View file @
a39e9a7
...
...
@@ -2,10 +2,10 @@ import 'dart:ui' as ui;
import
'package:flutter/material.dart'
;
import
'package:flutter/scheduler.dart'
;
import
'package:get/get_state_manager/src/simple/get_state.dart'
;
import
'../../get_core/get_core.dart'
;
import
'../../get_instance/src/bindings_interface.dart'
;
import
'../../get_state_manager/src/simple/get_state.dart'
;
import
'../../get_utils/get_utils.dart'
;
import
'../get_navigation.dart'
;
import
'dialog/dialog_route.dart'
;
...
...
lib/get_navigation/src/root/get_cupertino_app.dart
View file @
a39e9a7
...
...
@@ -51,7 +51,7 @@ class GetCupertinoApp extends StatelessWidget {
final
LogWriterCallback
?
logWriterCallback
;
final
bool
?
popGesture
;
final
SmartManagement
smartManagement
;
final
Bindings
?
initialBinding
;
final
Bindings
Interface
?
initialBinding
;
final
Duration
?
transitionDuration
;
final
bool
?
defaultGlobalState
;
final
List
<
GetPage
>?
getPages
;
...
...
lib/get_navigation/src/root/get_material_app.dart
View file @
a39e9a7
...
...
@@ -56,7 +56,7 @@ class GetMaterialApp extends StatelessWidget {
final
LogWriterCallback
?
logWriterCallback
;
final
bool
?
popGesture
;
final
SmartManagement
smartManagement
;
final
Bindings
?
initialBinding
;
final
Bindings
Interface
?
initialBinding
;
final
Duration
?
transitionDuration
;
final
bool
?
defaultGlobalState
;
final
List
<
GetPage
>?
getPages
;
...
...
lib/get_navigation/src/routes/default_route.dart
View file @
a39e9a7
...
...
@@ -61,7 +61,7 @@ class GetPageRoute<T> extends PageRoute<T> //MaterialPageRoute<T>
final
String
?
routeName
;
//final String reference;
final
CustomTransition
?
customTransition
;
final
Binding
?
binding
;
final
Binding
sInterface
?
binding
;
final
Map
<
String
,
String
>?
parameter
;
final
List
<
Bind
>?
binds
;
...
...
@@ -101,14 +101,32 @@ class GetPageRoute<T> extends PageRoute<T> //MaterialPageRoute<T>
if
(
_child
!=
null
)
return
_child
!;
final
middlewareRunner
=
MiddlewareRunner
(
middlewares
);
final
localbind
ing
s
=
[
final
localbinds
=
[
if
(
binds
!=
null
)
...
binds
!,
if
(
binding
!=
null
)
...
binding
!.
dependencies
(),
];
final
bindingsToBind
=
middlewareRunner
.
runOnBindingsStart
(
localbindings
);
final
localbindings
=
[
if
(
binding
!=
null
)
...<
BindingsInterface
>[
binding
!],
];
final
bindingsToBind
=
middlewareRunner
.
runOnBindingsStart
(
binding
!=
null
?
localbindings
:
localbinds
);
/// Retrocompatibility workaround, remove this when Bindings api
/// have been removed
if
(
bindingsToBind
!=
null
&&
bindingsToBind
is
!
List
<
Bind
>
&&
bindingsToBind
is
List
<
BindingsInterface
>)
{
for
(
final
binding
in
bindingsToBind
)
{
binding
.
dependencies
();
}
}
final
pageToBuild
=
middlewareRunner
.
runOnPageBuildStart
(
page
)!;
if
(
bindingsToBind
!=
null
&&
bindingsToBind
.
isNotEmpty
)
{
if
(
bindingsToBind
!=
null
&&
bindingsToBind
.
isNotEmpty
&&
bindingsToBind
is
List
<
Bind
>)
{
_child
=
Binds
(
child:
middlewareRunner
.
runOnPageBuilt
(
pageToBuild
()),
binds:
bindingsToBind
,
...
...
lib/get_navigation/src/routes/get_route.dart
View file @
a39e9a7
...
...
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
import
'package:flutter/material.dart'
;
import
'../../../get_core/src/get_main.dart'
;
import
'../../../get_instance/src/bindings_interface.dart'
;
import
'../../../get_state_manager/src/simple/get_state.dart'
;
import
'../../get_navigation.dart'
;
...
...
@@ -17,7 +18,7 @@ class GetPage<T> extends Page<T> {
final
bool
maintainState
;
final
bool
opaque
;
final
double
Function
(
BuildContext
context
)?
gestureWidth
;
final
Binding
?
binding
;
final
Binding
sInterface
?
binding
;
final
List
<
Bind
>
binds
;
final
CustomTransition
?
customTransition
;
final
Duration
?
transitionDuration
;
...
...
@@ -87,7 +88,7 @@ class GetPage<T> extends Page<T> {
Alignment
?
alignment
,
bool
?
maintainState
,
bool
?
opaque
,
Binding
?
binding
,
Binding
sInterface
?
binding
,
List
<
Bind
>?
binds
,
CustomTransition
?
customTransition
,
Duration
?
transitionDuration
,
...
...
lib/get_navigation/src/routes/route_middleware.dart
View file @
a39e9a7
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/foundation.dart'
;
import
'../../../get.dart'
;
abstract
class
_RouteMiddleware
{
...
...
@@ -77,7 +78,7 @@ abstract class _RouteMiddleware {
/// }
/// ```
/// {@end-tool}
List
<
Bind
>?
onBindingsStart
(
List
<
Bind
>
bindings
);
List
<
R
>?
onBindingsStart
<
R
>(
List
<
R
>
bindings
);
/// This function will be called right after the [Bindings] are initialize.
GetPageBuilder
?
onPageBuildStart
(
GetPageBuilder
page
);
...
...
@@ -107,7 +108,7 @@ class GetMiddleware implements _RouteMiddleware {
GetPage
?
onPageCalled
(
GetPage
?
page
)
=>
page
;
@override
List
<
Bind
>?
onBindingsStart
(
List
<
Bind
>?
bindings
)
=>
bindings
;
List
<
R
>?
onBindingsStart
<
R
>(
List
<
R
>?
bindings
)
=>
bindings
;
@override
GetPageBuilder
?
onPageBuildStart
(
GetPageBuilder
?
page
)
=>
page
;
...
...
@@ -155,7 +156,7 @@ class MiddlewareRunner {
return
to
;
}
List
<
Bind
>?
runOnBindingsStart
(
List
<
Bind
>?
bindings
)
{
List
<
R
>?
runOnBindingsStart
<
R
>(
List
<
R
>?
bindings
)
{
_getMiddlewares
().
forEach
((
element
)
{
bindings
=
element
.
onBindingsStart
(
bindings
);
});
...
...
lib/get_rx/src/rx_stream/rx_stream.dart
View file @
a39e9a7
...
...
@@ -2,8 +2,6 @@ library rx_stream;
import
'dart:async'
;
import
'package:get/get_state_manager/src/simple/list_notifier.dart'
;
import
'../rx_typedefs/rx_typedefs.dart'
;
import
'../rx_types/rx_types.dart'
;
...
...
lib/get_rx/src/rx_types/rx_core/rx_impl.dart
View file @
a39e9a7
...
...
@@ -292,12 +292,9 @@ extension RxBoolExt on Rx<bool> {
/// Toggles the bool [value] between false and true.
/// A shortcut for `flag.value = !flag.value;`
/// FIXME: why return this? fluent interface is not
/// not really a dart thing since we have '..' operator
// ignore: avoid_returning_this
Rx
<
bool
>
toggle
()
{
void
toggle
()
{
subject
.
add
(!
value
);
return
this
;
//
return this;
}
}
...
...
@@ -324,13 +321,10 @@ extension RxnBoolExt on Rx<bool?> {
/// Toggles the bool [value] between false and true.
/// A shortcut for `flag.value = !flag.value;`
/// FIXME: why return this? fluent interface is not
/// not really a dart thing since we have '..' operator
// ignore: avoid_returning_this
Rx
<
bool
?>?
toggle
()
{
void
toggle
()
{
if
(
value
!=
null
)
{
subject
.
add
(!
value
!);
return
this
;
//
return this;
}
}
}
...
...
lib/get_rx/src/rx_types/rx_types.dart
View file @
a39e9a7
...
...
@@ -4,7 +4,7 @@ import 'dart:async';
import
'dart:collection'
;
import
'package:flutter/foundation.dart'
;
import
'package:get/get_state_manager/src/simple/list_notifier.dart'
;
import
'../rx_stream/rx_stream.dart'
;
import
'../rx_typedefs/rx_typedefs.dart'
;
...
...
@@ -12,7 +12,6 @@ part 'rx_core/rx_impl.dart';
part
'rx_core/rx_interface.dart'
;
part
'rx_core/rx_num.dart'
;
part
'rx_core/rx_string.dart'
;
part
'rx_iterables/rx_list.dart'
;
part
'rx_iterables/rx_set.dart'
;
part
'rx_iterables/rx_map.dart'
;
part
'rx_iterables/rx_set.dart'
;
...
...
lib/get_state_manager/src/rx_flutter/rx_getx_widget.dart
View file @
a39e9a7
...
...
@@ -2,12 +2,11 @@ import 'dart:async';
import
'package:flutter/foundation.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:get/get_instance/src/lifecycle.dart'
;
import
'../../../get_core/get_core.dart'
;
import
'../../../get_instance/src/get_instance.dart'
;
import
'../../../get_instance/src/lifecycle.dart'
;
import
'../../../get_rx/src/rx_types/rx_types.dart'
;
import
'../../get_state_manager.dart'
;
typedef
GetXControllerBuilder
<
T
extends
GetLifeCycleMixin
>
=
Widget
Function
(
T
controller
);
...
...
lib/get_state_manager/src/rx_flutter/rx_obx_widget.dart
View file @
a39e9a7
...
...
@@ -35,7 +35,7 @@ class _ObxState extends State<ObxWidget> {
@override
void
initState
()
{
super
.
initState
();
subs
=
_observer
.
listen
(
_updateTree
,
cancelOnError:
false
);
subs
=
_observer
.
subject
.
stream
.
listen
(
_updateTree
,
cancelOnError:
false
);
}
void
_updateTree
(
_
)
{
...
...
lib/get_state_manager/src/simple/get_state.dart
View file @
a39e9a7
...
...
@@ -361,20 +361,8 @@ class BindWrapper<T> extends InheritedWidget {
this
.
didUpdateWidget
,
})
:
super
(
key:
key
,
child:
child
);
/// The [Listenable] object to which to listen.
///
/// Whenever this object sends change notifications, the dependents of this
/// widget are triggered.
///
/// By default, whenever the [controller] is changed (including when changing to
/// or from null), if the old controller is not equal to the new controller (as
/// determined by the `==` operator), notifications are sent. This behavior
/// can be overridden by overriding [updateShouldNotify].
///
/// While the [controller] is null, no notifications are sent, since the null
/// object cannot itself send notifications.
final
InitBuilder
<
T
>?
init
;
final
InitBuilder
<
T
>?
init
;
final
bool
global
;
final
Object
?
id
;
final
String
?
tag
;
...
...
@@ -411,7 +399,6 @@ class BindElement<T> extends InheritedElement {
T
?
_controller
;
T
get
controller
{
print
(
'get controller
$T
'
);
if
(
_controller
==
null
)
{
_controller
=
_controllerBuilder
?.
call
();
_subscribeToController
();
...
...
@@ -583,6 +570,7 @@ class BindError<T> extends Error {
/// instance of Bindings to manage the
/// dependencies() (via Get.put()) for the Route you are opening.
// ignore: one_member_abstracts
abstract
class
Binding
{
abstract
class
Binding
extends
BindingsInterface
<
List
<
Bind
>>
{
@override
List
<
Bind
>
dependencies
();
}
...
...
lib/get_state_manager/src/simple/list_notifier.dart
View file @
a39e9a7
...
...
@@ -11,14 +11,7 @@ typedef GetStateUpdate = void Function();
class
ListNotifier
extends
Listenable
with
ListNotifierMixin
{}
//mixin ListenableMixin implements Listenable {}
mixin
ListNotifierMixin
on
Listenable
{
// int _version = 0;
// int _microtask = 0;
// int get notifierVersion => _version;
// int get notifierMicrotask => _microtask;
List
<
GetStateUpdate
?>?
_updaters
=
<
GetStateUpdate
?>[];
HashMap
<
Object
?,
List
<
GetStateUpdate
>>?
_updatersGroupIds
=
...
...
@@ -28,16 +21,7 @@ mixin ListNotifierMixin on Listenable {
void
refresh
()
{
assert
(
_debugAssertNotDisposed
());
/// This debounce the call to update.
/// It prevent errors and duplicates builds
// if (_microtask == _version) {
// _microtask++;
// scheduleMicrotask(() {
// _version++;
// _microtask = _version;
_notifyUpdate
();
// });
// }
}
void
_notifyUpdate
()
{
...
...
@@ -58,17 +42,7 @@ mixin ListNotifierMixin on Listenable {
@protected
void
refreshGroup
(
Object
id
)
{
assert
(
_debugAssertNotDisposed
());
// /// This debounce the call to update.
// /// It prevent errors and duplicates builds
// if (_microtask == _version) {
// _microtask++;
// scheduleMicrotask(() {
// _version++;
// _microtask = _version;
_notifyIdUpdate
(
id
);
// });
// }
}
bool
_debugAssertNotDisposed
()
{
...
...
@@ -147,7 +121,6 @@ class TaskManager {
static TaskManager get instance => _instance ??= TaskManager._();
GetStateUpdate? _setter;
List<VoidCallback>? _remove;
void notify(List<GetStateUpdate?>? _updaters) {
...
...
Please
register
or
login
to post a comment