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-17 13:31:03 -0300
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
86372918d5fa76266c0f673339ac4b2661ec7bd7
86372918
2 parents
1145dd20
bbf00f85
add benchmarks from value notifier vs get value
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
57 deletions
lib/get_navigation/get_navigation.dart
lib/get_state_manager/src/rx_flutter/rx_obx_widget.dart
lib/get_utils/src/get_utils/get_utils.dart
test/src/extensions/string_extensions_test.dart
lib/get_navigation/get_navigation.dart
View file @
8637291
...
...
@@ -5,7 +5,6 @@ export 'src/extension_navigation.dart';
export
'src/root/root_widget.dart'
;
export
'src/routes/custom_transition.dart'
;
export
'src/routes/default_route.dart'
;
export
'src/routes/default_route.dart'
;
export
'src/routes/get_route.dart'
;
export
'src/routes/observers/route_observer.dart'
;
export
'src/routes/transitions_type.dart'
;
...
...
lib/get_state_manager/src/rx_flutter/rx_obx_widget.dart
View file @
8637291
...
...
@@ -4,22 +4,21 @@ import '../../../get_rx/get_rx.dart';
typedef
WidgetCallback
=
Widget
Function
();
/// The simplest reactive widget in GetX.
///
/// Just pass your Rx variable in the root scope of the callback to have it
/// automatically registered for changes.
/// The [ObxWidget] is the base for all GetX reactive widgets
///
/// final _name = "GetX".obs;
/// Obx(() => Text( _name.value )),... ;
class
Obx
extends
StatefulWidget
{
final
WidgetCallback
builder
;
const
Obx
(
this
.
builder
);
/// See also:
/// - [Obx]
/// - [ObxValue]
abstract
class
ObxWidget
extends
StatefulWidget
{
const
ObxWidget
({
Key
key
})
:
super
(
key:
key
);
_ObxState
createState
()
=>
_ObxState
();
@protected
Widget
build
();
}
class
_ObxState
extends
State
<
Obx
>
{
class
_ObxState
extends
State
<
Obx
Widget
>
{
RxInterface
_observer
;
StreamSubscription
subs
;
...
...
@@ -43,7 +42,7 @@ class _ObxState extends State<Obx> {
Widget
get
notifyChilds
{
final
observer
=
getObs
;
getObs
=
_observer
;
final
result
=
widget
.
build
er
();
final
result
=
widget
.
build
();
if
(!
_observer
.
canUpdate
)
{
throw
"""
[Get] the improper use of a GetX has been detected.
...
...
@@ -62,6 +61,22 @@ class _ObxState extends State<Obx> {
Widget
build
(
BuildContext
context
)
=>
notifyChilds
;
}
/// The simplest reactive widget in GetX.
///
/// Just pass your Rx variable in the root scope of the callback to have it
/// automatically registered for changes.
///
/// final _name = "GetX".obs;
/// Obx(() => Text( _name.value )),... ;
class
Obx
extends
ObxWidget
{
final
WidgetCallback
builder
;
const
Obx
(
this
.
builder
);
@override
Widget
build
()
=>
builder
();
}
/// Similar to Obx, but manages a local state.
/// Pass the initial data in constructor.
/// Useful for simple local states, like toggles, visibility, themes,
...
...
@@ -76,45 +91,12 @@ class _ObxState extends State<Obx> {
// TODO: change T to a proper Rx interface, that includes the accessor
// for ::value
class
ObxValue
<
T
extends
RxInterface
>
extends
Stateful
Widget
{
class
ObxValue
<
T
extends
RxInterface
>
extends
Obx
Widget
{
final
Widget
Function
(
T
)
builder
;
final
T
data
;
const
ObxValue
(
this
.
builder
,
this
.
data
,
{
Key
key
})
:
super
(
key:
key
);
_ObxValueState
createState
()
=>
_ObxValueState
();
}
class
_ObxValueState
extends
State
<
ObxValue
>
{
RxInterface
_observer
;
StreamSubscription
subs
;
_ObxValueState
()
{
_observer
=
Rx
();
}
@override
void
initState
()
{
subs
=
_observer
.
subject
.
stream
.
listen
((
data
)
=>
setState
(()
{}));
super
.
initState
();
}
@override
void
dispose
()
{
subs
.
cancel
();
_observer
.
close
();
super
.
dispose
();
}
Widget
get
notifyChilds
{
final
observer
=
getObs
;
getObs
=
_observer
;
// observable is implicity taken from the constructor.
final
result
=
widget
.
builder
(
widget
.
data
);
getObs
=
observer
;
return
result
;
}
@override
Widget
build
(
BuildContext
context
)
=>
notifyChilds
;
Widget
build
(
)
=>
builder
(
data
)
;
}
...
...
lib/get_utils/src/get_utils/get_utils.dart
View file @
8637291
...
...
@@ -204,7 +204,7 @@ class GetUtils {
/// Checks if string is phone number.
static
bool
isPhoneNumber
(
String
s
)
=>
hasMatch
(
s
,
r'^
(0|\+|(\+[0-9]{2,4}|\(\+?[0-9]{2,4}\)) ?)([0-9]*|\d{2,4}-\d{2,4}(-\d{2,4})?)
$'
);
r'^
[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*
$'
);
/// Checks if string is DateTime (UTC or Iso8601).
static
bool
isDateTime
(
String
s
)
=>
...
...
test/src/extensions/string_extensions_test.dart
View file @
8637291
...
...
@@ -239,14 +239,12 @@ void main() {
'(455) 443-8171'
,
'(915) 685-8658'
,
'(572) 207-1898'
,
// TODO those are failing, but they shouldn't
// '(81) 6 2499-9538',
// '(31) 32304-4263',
// '(64) 25242-6375',
// '(41) 19308-7925',
// '(67) 61684-0395',
// '(60) 54706-3569',
'(81) 6 2499-9538'
,
'(31) 32304-4263'
,
'(64) 25242-6375'
,
'(41) 19308-7925'
,
'(67) 61684-0395'
,
'(60) 54706-3569'
,
'(31) 33110055'
,
'(11) 3344-5599'
,
'(31) 977447788'
,
...
...
Please
register
or
login
to post a comment