-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #314 from ProximaEPFL/offline-circular-value
Offline Circular Value Adaptation
- Loading branch information
Showing
30 changed files
with
312 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import "package:flutter/material.dart"; | ||
|
||
/// A simple alert dialog that displays the offline error message. | ||
/// Used by the circular value when the future times out. | ||
class OfflineAlert extends StatelessWidget { | ||
static const okButtonKey = Key("offlineAlertOkButton"); | ||
|
||
static const errorMessage = | ||
"Your device is offline or has poor internet connectivity.\nPlease try again later."; | ||
|
||
/// Constructor for the [OfflineAlert] widget. | ||
const OfflineAlert({ | ||
super.key, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final okButton = TextButton( | ||
onPressed: Navigator.of(context).pop, | ||
key: okButtonKey, | ||
child: const Text("OK"), | ||
); | ||
|
||
return AlertDialog( | ||
title: const Text("Device offline"), | ||
content: const Text(errorMessage), | ||
actions: [okButton], | ||
); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/// Wrapper class to represent the result of a computation. | ||
/// It can take the form of a value [Result.value] | ||
/// or the form of an error [Result.error]. | ||
/// We use it to wrap a future instead of throwing an exception. | ||
/// Useful to wrap futures coming from a provider. | ||
class Result<V, E> { | ||
final V? value; | ||
final E? error; | ||
|
||
Result._(this.value, this.error); | ||
|
||
factory Result.value(V value) { | ||
return Result._(value, null); | ||
} | ||
|
||
factory Result.error(E error) { | ||
return Result._(null, error); | ||
} | ||
|
||
bool get isError => error != null; | ||
} | ||
|
||
/// Extention on [Future] to automatically wrap them in a [Result] | ||
/// instead of throwing an error. | ||
extension MapFutureRes<T> on Future<T> { | ||
Future<Result<T, Object?>> mapRes() { | ||
return then((value) => Result.value(value)) | ||
.onError((error, stackTrace) => Result<T, Object?>.error(error)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
lib/views/pages/home/content/ranking/components/ranking_list.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.