Skip to content

Commit

Permalink
Release/1.0.26 - Code formatting, remove lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
phillwiggins committed Mar 28, 2020
1 parent bb4eef6 commit 3163da6
Show file tree
Hide file tree
Showing 14 changed files with 152 additions and 108 deletions.
4 changes: 2 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class _MyAppState extends State<MyApp> {
Future<void> initData() async {
// Initialize repository
await initRepository();
final CoreStore coreStore = await initCoreStore();
await initCoreStore();

// Initialize parse
await Parse().initialize(keyParseApplicationId, keyParseServerUrl,
Expand Down Expand Up @@ -233,7 +233,7 @@ class _MyAppState extends State<MyApp> {
user = response.result;
}*/

ParseUser user1 = await ParseUser.currentUser();
final ParseUser user1 = await ParseUser.currentUser();
user1.authData;

/// Login
Expand Down
10 changes: 5 additions & 5 deletions example/lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class _HomePageState extends State<HomePage> {
if (snapshot.data.success) {
if (snapshot.data.results == null ||
snapshot.data.results.isEmpty) {
return Center(
child: const Text('No Data'),
return const Center(
child: Text('No Data'),
);
}
}
Expand All @@ -97,7 +97,7 @@ class _HomePageState extends State<HomePage> {
child: ListTile(
title: Text(
name,
style: TextStyle(fontSize: 20.0),
style: const TextStyle(fontSize: 20.0),
),
subtitle: Text(description),
trailing: IconButton(
Expand All @@ -118,8 +118,8 @@ class _HomePageState extends State<HomePage> {
);
});
} else {
return Center(
child: const Text('No Data'),
return const Center(
child: Text('No Data'),
);
}
});
Expand Down
10 changes: 5 additions & 5 deletions example/lib/pages/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class _LoginPageState extends State<LoginPage> {

Widget _showCircularProgress() {
if (_isLoading) {
return Center(child: const CircularProgressIndicator());
return const Center(child: CircularProgressIndicator());
}
return Container(
height: 0.0,
Expand Down Expand Up @@ -179,9 +179,9 @@ class _LoginPageState extends State<LoginPage> {
maxLines: 1,
keyboardType: TextInputType.emailAddress,
autofocus: false,
decoration: InputDecoration(
decoration: const InputDecoration(
hintText: 'Email',
icon: const Icon(
icon: Icon(
Icons.mail,
color: Colors.grey,
)),
Expand All @@ -199,9 +199,9 @@ class _LoginPageState extends State<LoginPage> {
maxLines: 1,
obscureText: true,
autofocus: false,
decoration: InputDecoration(
decoration: const InputDecoration(
hintText: 'Password',
icon: const Icon(
icon: Icon(
Icons.lock,
color: Colors.grey,
)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ void main() {
// When
final ApiResponse baseResponse = await repository.add(dummy);
final ApiResponse responseWithResult = await repository
.getNewerThan(DateTime.now().subtract(Duration(days: 1)));
.getNewerThan(DateTime.now().subtract(const Duration(days: 1)));
final ApiResponse responseWithoutResult =
await repository.getNewerThan(DateTime.now().add(Duration(days: 1)));
await repository.getNewerThan(
DateTime.now().add(const Duration(days: 1)));

// CLEAR FROM DB
await deleteFromApi(baseResponse.results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void main() {

// When
DateTime dateTime = DateTime.now();
dateTime = dateTime.subtract(Duration(hours: 1));
dateTime = dateTime.subtract(const Duration(hours: 1));
final ApiResponse updateResponse = await repository.getNewerThan(dateTime);
final List<DietPlan> actual = updateResponse.results;

Expand Down
30 changes: 0 additions & 30 deletions example_livelist/test/widget_test.dart

This file was deleted.

66 changes: 44 additions & 22 deletions lib/src/network/parse_live_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Subscription<T extends ParseObject> {
Subscription(this.query, this.requestId, {T copyObject}) {
_copyObject = copyObject;
}

QueryBuilder<T> query;
T _copyObject;
int requestId;
Expand All @@ -30,6 +31,7 @@ class Subscription<T extends ParseObject> {
'error'
];
Map<String, Function> eventCallbacks = <String, Function>{};

void on(LiveQueryEvent op, Function callback) {
eventCallbacks[_liveQueryEvent[op.index]] = callback;
}
Expand All @@ -42,21 +44,6 @@ class Subscription<T extends ParseObject> {
enum LiveQueryClientEvent { CONNECTED, DISCONNECTED, USER_DISCONNECTED }

class LiveQueryReconnectingController with WidgetsBindingObserver {
// -1 means "do not try to reconnect",
static const List<int> retryInterval = [0, 500, 1000, 2000, 5000, 10000];
static const String DEBUG_TAG = 'LiveQueryReconnectingController';

final Function _reconnect;
final Stream<LiveQueryClientEvent> _eventStream;
final bool debug;

int _retryState = 0;
bool _isOnline = false;
bool _isConnected = false;
bool _userDisconnected = false;

Timer _currentTimer;

LiveQueryReconnectingController(
this._reconnect, this._eventStream, this.debug) {
Connectivity().checkConnectivity().then(_connectivityChanged);
Expand All @@ -82,15 +69,36 @@ class LiveQueryReconnectingController with WidgetsBindingObserver {
break;
}

if (debug) print('$DEBUG_TAG: $event');
if (debug) {
print('$DEBUG_TAG: $event');
}
});
WidgetsBinding.instance.addObserver(this);
}

// -1 means "do not try to reconnect",
static const List<int> retryInterval = <int>[0, 500, 1000, 2000, 5000, 10000];
static const String DEBUG_TAG = 'LiveQueryReconnectingController';

final Function _reconnect;
final Stream<LiveQueryClientEvent> _eventStream;
final bool debug;

int _retryState = 0;
bool _isOnline = false;
bool _isConnected = false;
bool _userDisconnected = false;

Timer _currentTimer;

void _connectivityChanged(ConnectivityResult state) {
if (!_isOnline && state != ConnectivityResult.none) _retryState = 0;
if (!_isOnline && state != ConnectivityResult.none) {
_retryState = 0;
}
_isOnline = state != ConnectivityResult.none;
if (debug) print('$DEBUG_TAG: $state');
if (debug) {
print('$DEBUG_TAG: $state');
}
_setReconnect();
}

Expand Down Expand Up @@ -118,13 +126,16 @@ class LiveQueryReconnectingController with WidgetsBindingObserver {
});
if (debug)
print('$DEBUG_TAG: Retrytimer set to ${retryInterval[_retryState]}ms');
if (_retryState < retryInterval.length - 1) _retryState++;
if (_retryState < retryInterval.length - 1) {
_retryState++;
}
}
}
}

class Client {
factory Client() => _getInstance();

Client._internal(
{bool debug, ParseHTTPClient client, bool autoSendSessionId}) {
_clientEventStreamController = StreamController<LiveQueryClientEvent>();
Expand All @@ -150,8 +161,10 @@ class Client {
reconnectingController = LiveQueryReconnectingController(
() => reconnect(userInitialized: false), getClientEventStream, _debug);
}

static Client get instance => _getInstance();
static Client _instance;

static Client _getInstance(
{bool debug, ParseHTTPClient client, bool autoSendSessionId}) {
_instance ??= Client._internal(
Expand All @@ -174,6 +187,7 @@ class Client {
Stream<LiveQueryClientEvent> _clientEventStream;
LiveQueryReconnectingController reconnectingController;

// ignore: always_specify_types
final Map<int, Subscription> _requestSubScription = <int, Subscription>{};

Future<void> reconnect({bool userInitialized = false}) async {
Expand Down Expand Up @@ -203,8 +217,9 @@ class Client {
await _channel.sink.close();
_channel = null;
}
_requestSubScription.values.toList().forEach((Subscription subcription) {
subcription._enabled = false;
// ignore: always_specify_types
_requestSubScription.values.toList().forEach((Subscription subscription) {
subscription._enabled = false;
});
_connecting = false;
if (userInitialized)
Expand Down Expand Up @@ -327,12 +342,14 @@ class Client {
_channel.sink.add(jsonEncode(connectMessage));
}

// ignore: always_specify_types
void _subscribeLiveQuery(Subscription subscription) {
if (subscription._enabled) {
return;
}
subscription._enabled = true;
QueryBuilder query = subscription.query;
// ignore: always_specify_types
final QueryBuilder query = subscription.query;
final List<String> keysToReturn = query.limiters['keys']?.split(',');
query.limiters.clear(); //Remove limits in LiveQuery
final String _where = query.buildQuery().replaceAll('where=', '');
Expand Down Expand Up @@ -370,9 +387,11 @@ class Client {
}

final Map<String, dynamic> actionData = jsonDecode(message);
// ignore: always_specify_types
Subscription subscription;
if (actionData.containsKey('op') && actionData['op'] == 'connected') {
print('ReSubScription:$_requestSubScription');
// ignore: always_specify_types
_requestSubScription.values.toList().forEach((Subscription subcription) {
_subscribeLiveQuery(subcription);
});
Expand Down Expand Up @@ -423,11 +442,14 @@ class LiveQuery {
ParseHTTPClient _client;
bool _debug;
bool _sendSessionId;

// ignore: always_specify_types
Subscription _latestSubscription;
Client client;

// ignore: always_specify_types
@deprecated
// ignore: always_specify_types
Future<dynamic> subscribe(QueryBuilder query) async {
_latestSubscription = await client.subscribe(query);
return _latestSubscription;
Expand Down
Loading

0 comments on commit 3163da6

Please sign in to comment.