Skip to content

Commit ebb45e3

Browse files
committed
refactor(examples): remove repository layer from demo
1 parent f43ea11 commit ebb45e3

7 files changed

Lines changed: 134 additions & 585 deletions

File tree

examples/build.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,18 @@ Use **Provider** for dependency injection and **ChangeNotifier** for reactive st
6666
- `ChangeNotifierProvider<AppViewModel>` at the root widget tree in `main.dart`
6767
- `AppViewModel extends ChangeNotifier` holds all UI state as private fields with public getters
6868
- Exposes action methods that update state and call `notifyListeners()`
69-
- Receives `OneSignalRepository` and `PreferencesService` via constructor injection
69+
- Receives `OneSignalApiService` and `PreferencesService` via constructor injection
7070
- Initialize OneSignal SDK before `runApp()`
7171
- Use `Consumer`/`Selector` from Provider to scope rebuilds and minimize re-renders
72-
- `OneSignalRepository` is a plain Dart class (not a ChangeNotifier)
72+
- SDK calls (`OneSignal.User.*`, `OneSignal.Notifications.*`, `OneSignal.InAppMessages.*`, etc.) are invoked directly from `AppViewModel`. There is no repository wrapper.
73+
- `OneSignalApiService` is a plain Dart class that owns the OneSignal REST API calls (send notification, live activity update/end, fetch user). Not a ChangeNotifier.
7374

7475
### Persistence
7576

7677
- `PreferencesService` wraps `SharedPreferences`
7778
- In-memory lists use `List<MapEntry<String, String>>` for triggers, aliases, tags
7879
- Triggers list (`triggersList`) is NOT persisted to `SharedPreferences`
80+
- After fetching the user from the REST API, merge results into existing in-memory lists (`_mergePairs` for tag/alias maps, `_mergeUnique` for emails/SMS) so locally-added entries that have not yet round-tripped through the API are preserved.
7981

8082
### SDK State Restoration
8183

@@ -113,10 +115,9 @@ OneSignal.User.addObserver(...)
113115
### Notification Permission
114116
- Call `viewModel.promptPush()` in `initState()` of `HomeScreen`
115117

116-
### Loading Overlay
117-
- `CircularProgressIndicator` centered in a full-screen semi-transparent overlay
118-
- `Stack` + `Visibility` based on `isLoading` state
119-
- Use `await Future.delayed(const Duration(milliseconds: 100))` after setting state for render delay
118+
### Loading State
119+
- No global loading overlay; render an inline `CircularProgressIndicator` inside the section that owns the in-flight work (e.g. user section while `isLoading` is true).
120+
- The viewmodel uses a request-sequence counter (`_fetchSequence`) so stale REST results are dropped when a newer fetch is already in flight.
120121

121122
### SnackBar Messages
122123
- `AppSnackBar` extension on `BuildContext` defined in `theme.dart`
@@ -134,6 +135,7 @@ OneSignal.User.addObserver(...)
134135
- `MultiSelectRemoveDialog` uses `CheckboxListTile`
135136
- `TextEditingController`s are properly disposed in `StatefulWidget`s
136137
- JSON parsing via `jsonDecode` returns `Map<String, dynamic>` for Track Event
138+
- Single-field input prompts (e.g. login, add email/SMS, add trigger) reuse a single `SingleInputDialog` widget that takes `title`, `fieldLabel`, `confirmLabel`, and `semanticsLabel`. Avoid creating a per-screen dialog widget when one input is needed.
137139

138140
---
139141

@@ -152,8 +154,6 @@ examples/demo/
152154
│ │ ├── onesignal_api_service.dart
153155
│ │ ├── preferences_service.dart
154156
│ │ └── tooltip_helper.dart
155-
│ ├── repositories/
156-
│ │ └── onesignal_repository.dart
157157
│ ├── viewmodels/
158158
│ │ └── app_viewmodel.dart
159159
│ ├── screens/
@@ -165,7 +165,6 @@ examples/demo/
165165
│ ├── action_button.dart
166166
│ ├── app_text_field.dart
167167
│ ├── list_widgets.dart
168-
│ ├── loading_overlay.dart
169168
│ ├── dialogs.dart
170169
│ └── sections/
171170
│ ├── app_section.dart

examples/demo/lib/main.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import 'package:flutter_dotenv/flutter_dotenv.dart';
44
import 'package:onesignal_flutter/onesignal_flutter.dart';
55
import 'package:provider/provider.dart';
66

7-
import 'repositories/onesignal_repository.dart';
87
import 'screens/home_screen.dart';
98
import 'services/onesignal_api_service.dart';
109
import 'services/preferences_service.dart';
@@ -84,7 +83,6 @@ Future<void> main() async {
8483
final apiService = OneSignalApiService()
8584
..setAppId(appId)
8685
..setApiKey(apiKey);
87-
final repository = OneSignalRepository(apiService);
8886

8987
// Fetch tooltips in background
9088
TooltipHelper().init();
@@ -94,7 +92,7 @@ Future<void> main() async {
9492
runApp(
9593
ChangeNotifierProvider(
9694
create: (_) {
97-
final vm = AppViewModel(repository, prefs);
95+
final vm = AppViewModel(apiService, prefs);
9896
vm.setupObservers();
9997
vm.loadInitialState(appId);
10098
return vm;

examples/demo/lib/repositories/onesignal_repository.dart

Lines changed: 0 additions & 227 deletions
This file was deleted.

0 commit comments

Comments
 (0)