Skip to content

Instantly share code, notes, and snippets.

@nguyenchilong
Created July 5, 2020 09:02
Show Gist options
  • Save nguyenchilong/39326bd1a04c0a58e062dd93e53b7b56 to your computer and use it in GitHub Desktop.
Save nguyenchilong/39326bd1a04c0a58e062dd93e53b7b56 to your computer and use it in GitHub Desktop.

Revisions

  1. nguyenchilong created this gist Jul 5, 2020.
    30 changes: 30 additions & 0 deletions notifications_view_model.dart
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    mport 'package:redux/redux.dart';
    import 'package:saidlty/data/model/notification_data.dart';
    import 'package:saidlty/redux/action_report.dart';
    import 'package:saidlty/redux/app/app_state.dart';
    import 'package:saidlty/redux/notification/notification_actions.dart';

    class NotificationsViewModel {
    final Notification notification;
    final List<Notification> notifications;
    final Function(bool) getNotifications;
    final ActionReport getNotificationsReport;

    NotificationsViewModel({
    this.notification,
    this.notifications,
    this.getNotifications,
    this.getNotificationsReport,
    });

    static NotificationsViewModel fromStore(Store<AppState> store) {
    return NotificationsViewModel(
    notification: store.state.notificationState.notification,
    notifications: store.state.notificationState.notifications.values.toList() ?? [],
    getNotifications: (isRefresh) {
    store.dispatch(GetNotificationsAction(isRefresh: isRefresh));
    },
    getNotificationsReport: store.state.notificationState.status["GetNotificationsAction"],
    );
    }
    }