Jonny Borges
Committed by GitHub

Merge pull request #2010 from jonataslaw/format

run dart format and add more docs
... ... @@ -7,4 +7,4 @@ const Map<String, String> pt_BR = {
'total_infecteds': 'Total de infectados',
'details': 'Detalhes',
'total_recovered': 'Total de recuperados'
};
\ No newline at end of file
};
... ...
... ... @@ -3,7 +3,6 @@ import 'package:get/get.dart';
import '../controllers/dashboard_controller.dart';
class DashboardView extends GetView<DashboardController> {
@override
Widget build(BuildContext context) {
... ...
... ... @@ -138,7 +138,11 @@ class HeaderValue {
stringBuffer.write(_value);
if (parameters != null && parameters!.isNotEmpty) {
_parameters!.forEach((name, value) {
stringBuffer..write('; ')..write(name)..write('=')..write(value);
stringBuffer
..write('; ')
..write(name)
..write('=')
..write(value);
});
}
return stringBuffer.toString();
... ...
import 'dart:convert';
/// Signature for [SocketNotifier.addCloses].
typedef CloseSocket = void Function(Close);
/// Signature for [SocketNotifier.addMessages].
typedef MessageSocket = void Function(dynamic val);
/// Signature for [SocketNotifier.open].
typedef OpenSocket = void Function();
/// Wrapper class to message and reason from SocketNotifier
class Close {
final String? message;
final int? reason;
... ... @@ -12,12 +22,8 @@ class Close {
}
}
typedef OpenSocket = void Function();
typedef CloseSocket = void Function(Close);
typedef MessageSocket = void Function(dynamic val);
/// This class manages the transmission of messages over websockets using
/// GetConnect
class SocketNotifier {
List<void Function(dynamic)>? _onMessages = <MessageSocket>[];
Map<String, void Function(dynamic)>? _onEvents = <String, MessageSocket>{};
... ... @@ -26,22 +32,42 @@ class SocketNotifier {
late OpenSocket open;
void addMessages(MessageSocket socket) {
_onMessages!.add((socket));
/// subscribe to close events
void addCloses(CloseSocket socket) {
_onCloses!.add(socket);
}
/// subscribe to error events
void addErrors(CloseSocket socket) {
_onErrors!.add((socket));
}
/// subscribe to named events
void addEvents(String event, MessageSocket socket) {
_onEvents![event] = socket;
}
void addCloses(CloseSocket socket) {
_onCloses!.add(socket);
/// subscribe to message events
void addMessages(MessageSocket socket) {
_onMessages!.add((socket));
}
void addErrors(CloseSocket socket) {
_onErrors!.add((socket));
/// Dispose messages, events, closes and errors subscriptions
void dispose() {
_onMessages = null;
_onEvents = null;
_onCloses = null;
_onErrors = null;
}
/// Notify all subscriptions on [addCloses]
void notifyClose(Close err) {
for (var item in _onCloses!) {
item(err);
}
}
/// Notify all subscriptions on [addMessages]
void notifyData(dynamic data) {
for (var item in _onMessages!) {
item(data);
... ... @@ -51,12 +77,7 @@ class SocketNotifier {
}
}
void notifyClose(Close err) {
for (var item in _onCloses!) {
item(err);
}
}
/// Notify all subscriptions on [addErrors]
void notifyError(Close err) {
// rooms.removeWhere((key, value) => value.contains(_ws));
for (var item in _onErrors!) {
... ... @@ -72,15 +93,9 @@ class SocketNotifier {
if (_onEvents!.containsKey(event)) {
_onEvents![event]!(data);
}
// ignore: avoid_catches_without_on_clauses
} catch (_) {
return;
}
}
void dispose() {
_onMessages = null;
_onEvents = null;
_onCloses = null;
_onErrors = null;
}
}
... ...
... ... @@ -4,15 +4,8 @@ import 'dart:convert';
import 'dart:html';
import '../../../get_core/get_core.dart';
import 'socket_notifier.dart';
enum ConnectionStatus {
connecting,
connected,
closed,
}
class BaseWebSocket {
String url;
WebSocket? socket;
... ... @@ -21,6 +14,8 @@ class BaseWebSocket {
bool isDisposed = false;
bool allowSelfSigned;
ConnectionStatus? connectionStatus;
Timer? _t;
BaseWebSocket(
this.url, {
this.ping = const Duration(seconds: 5),
... ... @@ -30,9 +25,12 @@ class BaseWebSocket {
? url.replaceAll('https:', 'wss:')
: url.replaceAll('http:', 'ws:');
}
ConnectionStatus? connectionStatus;
Timer? _t;
void close([int? status, String? reason]) {
socket?.close(status, reason);
}
// ignore: use_setters_to_change_properties
void connect() {
try {
connectionStatus = ConnectionStatus.connecting;
... ... @@ -68,9 +66,18 @@ class BaseWebSocket {
}
}
// ignore: use_setters_to_change_properties
void onOpen(OpenSocket fn) {
socketNotifier!.open = fn;
void dispose() {
socketNotifier!.dispose();
socketNotifier = null;
isDisposed = true;
}
void emit(String event, dynamic data) {
send(jsonEncode({'type': event, 'data': data}));
}
void on(String event, MessageSocket message) {
socketNotifier!.addEvents(event, message);
}
void onClose(CloseSocket fn) {
... ... @@ -85,12 +92,8 @@ class BaseWebSocket {
socketNotifier!.addMessages(fn);
}
void on(String event, MessageSocket message) {
socketNotifier!.addEvents(event, message);
}
void close([int? status, String? reason]) {
socket?.close(status, reason);
void onOpen(OpenSocket fn) {
socketNotifier!.open = fn;
}
void send(dynamic data) {
... ... @@ -103,14 +106,10 @@ class BaseWebSocket {
Get.log('WebSocket not connected, message $data not sent');
}
}
}
void emit(String event, dynamic data) {
send(jsonEncode({'type': event, 'data': data}));
}
void dispose() {
socketNotifier!.dispose();
socketNotifier = null;
isDisposed = true;
}
enum ConnectionStatus {
connecting,
connected,
closed,
}
... ...
... ... @@ -4,30 +4,28 @@ import 'dart:io';
import 'dart:math';
import '../../../get_core/get_core.dart';
import 'socket_notifier.dart';
enum ConnectionStatus {
connecting,
connected,
closed,
}
class BaseWebSocket {
String url;
WebSocket? socket;
SocketNotifier? socketNotifier = SocketNotifier();
bool isDisposed = false;
Duration ping;
bool allowSelfSigned;
ConnectionStatus? connectionStatus;
BaseWebSocket(
this.url, {
this.ping = const Duration(seconds: 5),
this.allowSelfSigned = true,
});
Duration ping;
bool allowSelfSigned;
ConnectionStatus? connectionStatus;
void close([int? status, String? reason]) {
socket?.close(status, reason);
}
// ignore: use_setters_to_change_properties
Future connect() async {
if (isDisposed) {
socketNotifier = SocketNotifier();
... ... @@ -60,9 +58,18 @@ class BaseWebSocket {
}
}
// ignore: use_setters_to_change_properties
void onOpen(OpenSocket fn) {
socketNotifier!.open = fn;
void dispose() {
socketNotifier!.dispose();
socketNotifier = null;
isDisposed = true;
}
void emit(String event, dynamic data) {
send(jsonEncode({'type': event, 'data': data}));
}
void on(String event, MessageSocket message) {
socketNotifier!.addEvents(event, message);
}
void onClose(CloseSocket fn) {
... ... @@ -77,12 +84,8 @@ class BaseWebSocket {
socketNotifier!.addMessages(fn);
}
void on(String event, MessageSocket message) {
socketNotifier!.addEvents(event, message);
}
void close([int? status, String? reason]) {
socket?.close(status, reason);
void onOpen(OpenSocket fn) {
socketNotifier!.open = fn;
}
void send(dynamic data) async {
... ... @@ -95,16 +98,6 @@ class BaseWebSocket {
}
}
void dispose() {
socketNotifier!.dispose();
socketNotifier = null;
isDisposed = true;
}
void emit(String event, dynamic data) {
send(jsonEncode({'type': event, 'data': data}));
}
Future<WebSocket> _connectForSelfSignedCert(String url) async {
try {
var r = Random();
... ... @@ -136,3 +129,9 @@ class BaseWebSocket {
}
}
}
enum ConnectionStatus {
connecting,
connected,
closed,
}
... ...
... ... @@ -816,7 +816,16 @@ you can only use widgets and widget functions here''';
bool canPop = true,
int? id,
}) {
//TODO: This code brings compatibility of the new snackbar with GetX 4,
// remove this code in version 5
if (isSnackbarOpen && !closeOverlays) {
closeCurrentSnackbar();
return;
}
if (closeOverlays && isOverlaysOpen) {
//TODO: This code brings compatibility of the new snackbar with GetX 4,
// remove this code in version 5
if (isSnackbarOpen) {
closeAllSnackbars();
}
... ... @@ -1111,8 +1120,8 @@ you can only use widgets and widget functions here''';
SnackbarController.cancelAllSnackbars();
}
void closeCurrentSnackbar() {
SnackbarController.closeCurrentSnackbar();
Future<void> closeCurrentSnackbar() async {
await SnackbarController.closeCurrentSnackbar();
}
/// check if dialog is open
... ...
... ... @@ -9,24 +9,6 @@ import '../../get_navigation.dart';
import 'custom_transition.dart';
import 'transitions_type.dart';
@immutable
class PathDecoded {
const PathDecoded(this.regex, this.keys);
final RegExp regex;
final List<String?> keys;
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is PathDecoded &&
other.regex == regex; // && listEquals(other.keys, keys);
}
@override
int get hashCode => regex.hashCode;
}
class GetPage<T> extends Page<T> {
final GetPageBuilder page;
final bool? popGesture;
... ... @@ -98,27 +80,6 @@ class GetPage<T> extends Page<T> {
);
// settings = RouteSettings(name: name, arguments: Get.arguments);
static PathDecoded _nameToRegex(String path) {
var keys = <String?>[];
String _replace(Match pattern) {
var buffer = StringBuffer('(?:');
if (pattern[1] != null) buffer.write('\.');
buffer.write('([\\w%+-._~!\$&\'()*,;=:@]+))');
if (pattern[3] != null) buffer.write('?');
keys.add(pattern[2]);
return "$buffer";
}
var stringPath = '$path/?'
.replaceAllMapped(RegExp(r'(\.)?:(\w+)(\?)?'), _replace)
.replaceAll('//', '/');
return PathDecoded(RegExp('^$stringPath\$'), keys);
}
GetPage<T> copy({
String? name,
GetPageBuilder? page,
... ... @@ -174,8 +135,6 @@ class GetPage<T> extends Page<T> {
);
}
late Future<T?> popped;
@override
Route<T> createRoute(BuildContext context) {
// return GetPageRoute<T>(settings: this, page: page);
... ... @@ -185,7 +144,45 @@ class GetPage<T> extends Page<T> {
unknownRoute: unknownRoute,
).getPageToRoute<T>(this, unknownRoute);
popped = _page.popped;
return _page;
}
static PathDecoded _nameToRegex(String path) {
var keys = <String?>[];
String _replace(Match pattern) {
var buffer = StringBuffer('(?:');
if (pattern[1] != null) buffer.write('\.');
buffer.write('([\\w%+-._~!\$&\'()*,;=:@]+))');
if (pattern[3] != null) buffer.write('?');
keys.add(pattern[2]);
return "$buffer";
}
var stringPath = '$path/?'
.replaceAllMapped(RegExp(r'(\.)?:(\w+)(\?)?'), _replace)
.replaceAll('//', '/');
return PathDecoded(RegExp('^$stringPath\$'), keys);
}
}
@immutable
class PathDecoded {
final RegExp regex;
final List<String?> keys;
const PathDecoded(this.regex, this.keys);
@override
int get hashCode => regex.hashCode;
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is PathDecoded &&
other.regex == regex; // && listEquals(other.keys, keys);
}
}
... ...
... ... @@ -113,7 +113,6 @@ class GetObserver extends NavigatorObserver {
value.route = route;
value.isBack = false;
value.removed = '';
// value.isSnackbar = newRoute.isSnackbar ? true : value.isSnackbar ?? false;
value.isBottomSheet =
newRoute.isBottomSheet ? true : value.isBottomSheet ?? false;
value.isDialog = newRoute.isDialog ? true : value.isDialog ?? false;
... ...
... ... @@ -12,7 +12,7 @@ class SnackbarController {
late Animation<double> _filterBlurAnimation;
late Animation<Color?> _filterColorAnimation;
final GetSnackBar snack;
final GetSnackBar snackbar;
final _transitionCompleter = Completer<SnackbarController>();
late SnackbarStatusCallback? _snackbarStatus;
... ... @@ -40,15 +40,19 @@ class SnackbarController {
OverlayState? _overlayState;
SnackbarController(this.snack);
SnackbarController(this.snackbar);
Future<SnackbarController> get future => _transitionCompleter.future;
/// Close the snackbar with animation
Future<void> close() async {
_removeEntry();
await future;
}
/// Adds GetSnackbar to a view queue.
/// Only one GetSnackbar will be displayed at a time, and this method returns
/// a future to when the snackbar disappears.
Future<void> show() {
return _snackBarQueue.addJob(this);
}
... ... @@ -61,7 +65,7 @@ class SnackbarController {
// ignore: avoid_returning_this
void _configureAlignment(SnackPosition snackPosition) {
switch (snack.snackPosition) {
switch (snackbar.snackPosition) {
case SnackPosition.TOP:
{
_initialAlignment = const Alignment(-1.0, -2.0);
... ... @@ -89,8 +93,8 @@ class SnackbarController {
assert(!_transitionCompleter.isCompleted,
'Cannot configure a snackbar after disposing it.');
_controller = _createAnimationController();
_configureAlignment(snack.snackPosition);
_snackbarStatus = snack.snackbarStatus;
_configureAlignment(snackbar.snackPosition);
_snackbarStatus = snackbar.snackbarStatus;
_filterBlurAnimation = _createBlurFilterAnimation();
_filterColorAnimation = _createColorOverlayColor();
_animation = _createAnimation();
... ... @@ -100,11 +104,11 @@ class SnackbarController {
}
void _configureTimer() {
if (snack.duration != null) {
if (snackbar.duration != null) {
if (_timer != null && _timer!.isActive) {
_timer!.cancel();
}
_timer = Timer(snack.duration!, _removeEntry);
_timer = Timer(snackbar.duration!, _removeEntry);
} else {
if (_timer != null) {
_timer!.cancel();
... ... @@ -121,8 +125,8 @@ class SnackbarController {
return AlignmentTween(begin: _initialAlignment, end: _endAlignment).animate(
CurvedAnimation(
parent: _controller,
curve: snack.forwardAnimationCurve,
reverseCurve: snack.reverseAnimationCurve,
curve: snackbar.forwardAnimationCurve,
reverseCurve: snackbar.reverseAnimationCurve,
),
);
}
... ... @@ -133,16 +137,16 @@ class SnackbarController {
AnimationController _createAnimationController() {
assert(!_transitionCompleter.isCompleted,
'Cannot create a animationController from a disposed snackbar');
assert(snack.animationDuration >= Duration.zero);
assert(snackbar.animationDuration >= Duration.zero);
return AnimationController(
duration: snack.animationDuration,
duration: snackbar.animationDuration,
debugLabel: '$runtimeType',
vsync: navigator!,
);
}
Animation<double> _createBlurFilterAnimation() {
return Tween(begin: 0.0, end: snack.overlayBlur).animate(
return Tween(begin: 0.0, end: snackbar.overlayBlur).animate(
CurvedAnimation(
parent: _controller,
curve: const Interval(
... ... @@ -155,7 +159,8 @@ class SnackbarController {
}
Animation<Color?> _createColorOverlayColor() {
return ColorTween(begin: const Color(0x00000000), end: snack.overlayColor)
return ColorTween(
begin: const Color(0x00000000), end: snackbar.overlayColor)
.animate(
CurvedAnimation(
parent: _controller,
... ... @@ -170,11 +175,11 @@ class SnackbarController {
Iterable<OverlayEntry> _createOverlayEntries(Widget child) {
return <OverlayEntry>[
if (snack.overlayBlur > 0.0) ...[
if (snackbar.overlayBlur > 0.0) ...[
OverlayEntry(
builder: (context) => GestureDetector(
onTap: () {
if (snack.isDismissible && !_onTappedDismiss) {
if (snackbar.isDismissible && !_onTappedDismiss) {
_onTappedDismiss = true;
Get.back();
}
... ... @@ -202,7 +207,7 @@ class SnackbarController {
builder: (context) => Semantics(
child: AlignTransition(
alignment: _animation,
child: snack.isDismissible
child: snackbar.isDismissible
? _getDismissibleSnack(child)
: _getSnackbarContainer(child),
),
... ... @@ -219,14 +224,16 @@ class SnackbarController {
Widget _getBodyWidget() {
return Builder(builder: (_) {
return GestureDetector(
child: snack,
onTap: snack.onTap != null ? () => snack.onTap?.call(snack) : null,
child: snackbar,
onTap: snackbar.onTap != null
? () => snackbar.onTap?.call(snackbar)
: null,
);
});
}
DismissDirection _getDefaultDismissDirection() {
if (snack.snackPosition == SnackPosition.TOP) {
if (snackbar.snackPosition == SnackPosition.TOP) {
return DismissDirection.up;
}
return DismissDirection.down;
... ... @@ -234,7 +241,7 @@ class SnackbarController {
Widget _getDismissibleSnack(Widget child) {
return Dismissible(
direction: snack.dismissDirection ?? _getDefaultDismissDirection(),
direction: snackbar.dismissDirection ?? _getDefaultDismissDirection(),
resizeDuration: null,
confirmDismiss: (_) {
if (_currentStatus == SnackbarStatus.OPENING ||
... ... @@ -253,7 +260,7 @@ class SnackbarController {
Widget _getSnackbarContainer(Widget child) {
return Container(
margin: snack.margin,
margin: snackbar.margin,
child: child,
);
}
... ... @@ -327,8 +334,8 @@ class SnackbarController {
_snackBarQueue.cancelAllJobs();
}
static void closeCurrentSnackbar() {
_snackBarQueue.closeCurrentJob();
static Future<void> closeCurrentSnackbar() async {
await _snackBarQueue.closeCurrentJob();
}
}
... ... @@ -355,7 +362,7 @@ class _SnackBarQueue {
_queue.cancelAllJobs();
}
void closeCurrentJob() {
_currentSnackbar?.close();
Future<void> closeCurrentJob() async {
await _currentSnackbar?.close();
}
}
... ...
... ... @@ -40,12 +40,16 @@ void main() {
});
test('Get start and delete called just one time', () async {
Get..put(Controller())..put(Controller());
Get
..put(Controller())
..put(Controller());
final controller = Get.find<Controller>();
expect(controller.init, 1);
Get..delete<Controller>()..delete<Controller>();
Get
..delete<Controller>()
..delete<Controller>();
expect(controller.close, 1);
Get.reset();
});
... ...