Jonatas

update to 3.16.1

## [3.16.1]
- Fix compilation error on master
## [3.16.0]
- Documentation translated into Russian language. (@Renat Fakhrutdinov, @Doaxan and @BatttA)
- Added error message callback for StateMixin (@eduardoflorence)
... ...
... ... @@ -43,8 +43,8 @@ class BindingsBuilder<T> extends Bindings {
/// ```
factory BindingsBuilder.put(InstanceBuilderCallback<T> builder,
{String tag, bool permanent = false}) {
return BindingsBuilder(() => GetInstance()
.put<T>(null, tag: tag, permanent: permanent, builder: builder));
return BindingsBuilder(
() => GetInstance().put<T>(builder(), tag: tag, permanent: permanent));
}
/// WARNING: don't use `()=> Get.put(Controller())`,
... ...
... ... @@ -83,8 +83,7 @@ extension Inst on GetInterface {
{String tag,
bool permanent = false,
InstanceBuilderCallback<S> builder}) =>
GetInstance()
.put<S>(dependency, tag: tag, permanent: permanent, builder: builder);
GetInstance().put<S>(dependency, tag: tag, permanent: permanent);
/// Clears all registered instances (and/or tags).
/// Even the persistent ones.
... ...
import 'dart:ui';
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
... ... @@ -229,7 +229,8 @@ extension ExtensionDialog on GetInterface {
assert(useRootNavigator != null);
assert(debugCheckHasMaterialLocalizations(context));
final theme = Theme.of(context, shadowThemeOnly: true);
// final theme = Theme.of(context, shadowThemeOnly: true);
final theme = Theme.of(context);
return generalDialog<T>(
pageBuilder: (buildContext, animation, secondaryAnimation) {
final pageChild = widget;
... ... @@ -425,7 +426,8 @@ extension ExtensionBottomSheet on GetInterface {
.push(GetModalBottomSheetRoute<T>(
builder: (_) => bottomsheet,
isPersistent: persistent,
theme: Theme.of(key.currentContext, shadowThemeOnly: true),
// theme: Theme.of(key.currentContext, shadowThemeOnly: true),
theme: Theme.of(key.currentContext),
isScrollControlled: isScrollControlled,
barrierLabel:
MaterialLocalizations.of(key.currentContext).modalBarrierDismissLabel,
... ... @@ -1042,7 +1044,7 @@ Since version 2.8 it is possible to access the properties
}
///The window to which this binding is bound.
Window get window => engine.window;
ui.Window get window => ui.window;
///The number of device pixels for each logical pixel.
double get pixelRatio => window.devicePixelRatio;
... ...
... ... @@ -5,11 +5,7 @@ part of rx_types;
/// of those `Widgets` and Rx values.
RxInterface getObs;
mixin RxObjectMixin<T> {
GetStream<T> subject = GetStream<T>();
final _subscriptions = <StreamSubscription>[];
bool get canUpdate => _subscriptions.isNotEmpty;
mixin RxObjectMixin<T> on NotifyManager<T> {
T _value;
/// Makes a direct update of [value] adding it to the Stream
... ... @@ -48,15 +44,6 @@ mixin RxObjectMixin<T> {
subject.add(_value = null);
}
/// Closes the subscriptions for this Rx, releasing the resources.
void close() {
for (final subscription in _subscriptions) {
subscription?.cancel();
}
_subscriptions.clear();
subject.close();
}
/// Makes this Rx looks like a function so you can update a new
/// value using [rx(someOtherValue)]. Practical to assign the Rx directly
/// to some Widget that has a signature ::onChange( value )
... ... @@ -80,19 +67,6 @@ mixin RxObjectMixin<T> {
return value;
}
/// This is an internal method.
/// Subscribe to changes on the inner stream.
void addListener(GetStream<T> rxGetx) {
if (_subscriptions.contains(rxGetx.listen)) {
return;
}
final subs = rxGetx.listen((data) {
subject.add(data);
});
_subscriptions.add(subs);
}
bool firstRebuild = true;
/// Same as `toString()` but using a getter.
... ... @@ -111,7 +85,7 @@ mixin RxObjectMixin<T> {
bool operator ==(dynamic o) {
// Todo, find a common implementation for the hashCode of different Types.
if (o is T) return value == o;
if (o is RxInterface<T>) return value == o.value;
if (o is RxObjectMixin<T>) return value == o.value;
return false;
}
... ... @@ -138,6 +112,36 @@ mixin RxObjectMixin<T> {
Stream<T> get stream => GetStreamTransformation<T>(subject.listenable);
/// Binds an existing [Stream<T>] to this Rx<T> to keep the values in sync.
/// You can bind multiple sources to update the value.
/// Closing the subscription will happen automatically when the observer
/// Widget ([GetX] or [Obx]) gets unmounted from the Widget tree.
void bindStream(Stream<T> stream) {
_subscriptions.add(stream.listen((va) => value = va));
}
}
class RxNotifier<T> = RxInterface<T> with NotifyManager<T>;
mixin NotifyManager<T> {
GetStream<T> subject = GetStream<T>();
final _subscriptions = <StreamSubscription>[];
bool get canUpdate => _subscriptions.isNotEmpty;
/// This is an internal method.
/// Subscribe to changes on the inner stream.
void addListener(GetStream<T> rxGetx) {
if (_subscriptions.contains(rxGetx.listen)) {
return;
}
final subs = rxGetx.listen((data) {
subject.add(data);
});
_subscriptions.add(subs);
}
StreamSubscription<T> listen(
void Function(T) onData, {
Function onError,
... ... @@ -147,17 +151,18 @@ mixin RxObjectMixin<T> {
subject.listen(onData,
onError: onError, onDone: onDone, cancelOnError: cancelOnError);
/// Binds an existing [Stream<T>] to this Rx<T> to keep the values in sync.
/// You can bind multiple sources to update the value.
/// Closing the subscription will happen automatically when the observer
/// Widget ([GetX] or [Obx]) gets unmounted from the Widget tree.
void bindStream(Stream<T> stream) {
_subscriptions.add(stream.listen((va) => value = va));
/// Closes the subscriptions for this Rx, releasing the resources.
void close() {
for (final subscription in _subscriptions) {
subscription?.cancel();
}
_subscriptions.clear();
subject.close();
}
}
/// Base Rx class that manages all the stream logic for any Type.
abstract class _RxImpl<T> with RxObjectMixin<T> implements RxInterface<T> {
abstract class _RxImpl<T> extends RxNotifier<T> with RxObjectMixin<T> {
_RxImpl(T initial) {
_value = initial;
}
... ...
... ... @@ -7,23 +7,15 @@ part of rx_types;
abstract class RxInterface<T> {
RxInterface([T initial]);
GetStream<T> subject;
bool get canUpdate;
/// Adds a listener to stream
void addListener(GetStream<T> rxGetx);
bool get canUpdate;
set value(T val);
T get value;
/// Closes the stream
// FIXME: shouldn't we expose the returned future?
/// Close the Rx Variable
void close();
/// Calls [callback] with current value, when the value changes.
StreamSubscription<T> listen(void Function(T event) onData,
{Function onError, void Function() onDone, bool cancelOnError});
}
... ...
... ... @@ -2,7 +2,7 @@ part of rx_types;
/// Create a list similar to `List<T>`
class RxList<E> extends ListMixin<E>
with RxObjectMixin<List<E>>
with NotifyManager<List<E>>, RxObjectMixin<List<E>>
implements RxInterface<List<E>> {
RxList([List<E> initial]) {
_value = initial;
... ...
part of rx_types;
class RxMap<K, V> extends MapMixin<K, V>
with RxObjectMixin<Map<K, V>>
with NotifyManager<Map<K, V>>, RxObjectMixin<Map<K, V>>
implements RxInterface<Map<K, V>> {
RxMap([Map<K, V> initial]) {
_value = initial;
_value = initial;
}
@override
... ...
part of rx_types;
class RxSet<E> extends SetMixin<E>
with RxObjectMixin<Set<E>>
with NotifyManager<Set<E>>, RxObjectMixin<Set<E>>
implements RxInterface<Set<E>> {
RxSet([Set<E> initial]) {
if (initial != null) _value = initial;
... ... @@ -71,8 +71,6 @@ class RxSet<E> extends SetMixin<E>
refresh();
}
@override
bool add(E value) {
final val = _value.add(value);
... ...
... ... @@ -45,7 +45,7 @@ typedef WorkerCallback<T> = Function(T callback);
/// ```
Worker ever<T>(RxInterface<T> listener, WorkerCallback<T> callback,
{dynamic condition = true}) {
StreamSubscription sub = listener.subject.listen((event) {
StreamSubscription sub = listener.listen((event) {
if (_conditional(condition)) callback(event);
});
return Worker(sub.cancel, '[ever]');
... ... @@ -59,7 +59,7 @@ Worker everAll(List<RxInterface> listeners, WorkerCallback callback,
{dynamic condition = true}) {
final evers = <StreamSubscription>[];
for (var i in listeners) {
final sub = i.subject.listen((event) {
final sub = i.listen((event) {
if (_conditional(condition)) callback(event);
});
evers.add(sub);
... ... @@ -100,7 +100,7 @@ Worker once<T>(RxInterface<T> listener, WorkerCallback<T> callback,
{dynamic condition}) {
Worker ref;
StreamSubscription sub;
sub = listener.subject.listen((event) {
sub = listener.listen((event) {
if (!_conditional(condition)) return;
ref._disposed = true;
ref._log('called');
... ... @@ -132,7 +132,7 @@ Worker interval<T>(RxInterface<T> listener, WorkerCallback<T> callback,
{Duration time = const Duration(seconds: 1), dynamic condition = true}) {
var debounceActive = false;
time ??= const Duration(seconds: 1);
StreamSubscription sub = listener.subject.listen((event) async {
StreamSubscription sub = listener.listen((event) async {
if (debounceActive || !_conditional(condition)) return;
debounceActive = true;
await Future.delayed(time);
... ... @@ -165,7 +165,7 @@ Worker debounce<T>(RxInterface<T> listener, WorkerCallback<T> callback,
{Duration time}) {
final _debouncer =
Debouncer(delay: time ?? const Duration(milliseconds: 800));
StreamSubscription sub = listener.subject.listen((event) {
StreamSubscription sub = listener.listen((event) {
_debouncer(() {
callback(event);
});
... ...
... ... @@ -43,6 +43,9 @@ class GetX<T extends DisposableInterface> extends StatefulWidget {
}
class GetXState<T extends DisposableInterface> extends State<GetX<T>> {
GetXState() {
_observer = RxNotifier();
}
RxInterface _observer;
T controller;
bool isCreator = false;
... ... @@ -50,7 +53,6 @@ class GetXState<T extends DisposableInterface> extends State<GetX<T>> {
@override
void initState() {
_observer = Rx();
var isPrepared = GetInstance().isPrepared<T>(tag: widget.tag);
var isRegistered = GetInstance().isRegistered<T>(tag: widget.tag);
... ... @@ -77,7 +79,7 @@ class GetXState<T extends DisposableInterface> extends State<GetX<T>> {
if (widget.global && Get.smartManagement == SmartManagement.onlyBuilder) {
controller?.onStart();
}
subs = _observer.subject.listen((data) => setState(() {}));
subs = _observer.listen((data) => setState(() {}));
super.initState();
}
... ...
... ... @@ -24,12 +24,12 @@ class _ObxState extends State<ObxWidget> {
StreamSubscription subs;
_ObxState() {
_observer = Rx();
_observer = RxNotifier();
}
@override
void initState() {
subs = _observer.subject.listen((data) => setState(() {}));
subs = _observer.listen((data) => setState(() {}));
super.initState();
}
... ... @@ -89,9 +89,6 @@ class Obx extends ObxWidget {
/// ),
/// false.obs,
/// ),
// TODO: change T to a proper Rx interface, that includes the accessor
// for ::value
class ObxValue<T extends RxInterface> extends ObxWidget {
final Widget Function(T) builder;
final T data;
... ... @@ -101,3 +98,24 @@ class ObxValue<T extends RxInterface> extends ObxWidget {
@override
Widget build() => builder(data);
}
/// Similar to Obx, but manages a local state.
/// Pass the initial data in constructor.
/// Useful for simple local states, like toggles, visibility, themes,
/// button states, etc.
/// Sample:
/// ObxValue((data) => Switch(
/// value: data.value,
/// onChanged: (flag) => data.value = flag,
/// ),
/// false.obs,
/// ),
class RxValue<T> extends ObxWidget {
final Widget Function(T data) builder;
final Rx<T> data = Rx<T>();
RxValue(this.builder, {Key key}) : super(key: key);
@override
Widget build() => builder(data.value);
}
... ...
... ... @@ -94,7 +94,7 @@ class GetUtils {
/// Checks if string consist only Alphabet. (No Whitespace)
static bool isAlphabetOnly(String s) => hasMatch(s, r'^[a-zA-Z]+$');
/// Checks if string contains at least one Capital Letter
static bool hasCapitalletter(String s) => hasMatch(s, r'[A-Z]');
... ...
name: get
description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with GetX.
version: 3.15.0
version: 3.16.1
homepage: https://github.com/jonataslaw/getx
environment:
... ...