Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@locskot
Created June 11, 2021 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save locskot/c343d7a46845e9fc6973afa2dc8400e3 to your computer and use it in GitHub Desktop.
Save locskot/c343d7a46845e9fc6973afa2dc8400e3 to your computer and use it in GitHub Desktop.
import 'package:components/api/graphql_api.dart';
import 'package:components/model/request_result_model.dart';
import 'package:components/utils/log_service.dart';
import 'notification.dart';
abstract class NotificationsRepository {
NotificationsRepository();
factory NotificationsRepository.create(GraphqlAPI graphqlAPI) {
return NotificationRepositoryImpl(graphqlAPI);
}
Future<RequestResultModel> loadNotifications();
Future<RequestResultModel> markAsRead(List<String> data);
}
class NotificationRepositoryImpl extends NotificationsRepository {
GraphqlAPI graphqlAPI;
NotificationRepositoryImpl(this.graphqlAPI);
@override
Future<RequestResultModel> loadNotifications() async {
try {
final response = await Future.delayed(Duration(seconds: 2));
return RequestResultModel(result: true, value: mockItems());
} on Exception catch (e) {
LogService.log('Exception during loading notifications', exception: e);
return RequestResultModel(result: false, value: e);
}
}
@override
Future<RequestResultModel> markAsRead(List<String> data) async {
try {
final response = await Future.delayed(Duration(seconds: 2));
return RequestResultModel(result: true, value: data);
} on Exception catch (e) {
LogService.log('Exception during marking notifications as read', exception: e);
return RequestResultModel(result: false, value: e);
}
}
}
List<MockNotification> mockItems() {
final list = <MockNotification>[];
for (var i = 1; i < 100; i++) {
list.add(
MockNotification(
id: '$i',
label: 'Label $i',
dateTime: DateTime.now().subtract(
Duration(days: 1),
),
isRead: i % 2 == 0,
),
);
}
return list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment