Skip to content

Commit

Permalink
Migrate to Provider (#636)
Browse files Browse the repository at this point in the history
### Summary by Entelligence.AI

- New Feature: Introduced new provider classes (`MemoryProvider`,
`PluginProvider`, `CaptureProvider`, `AuthProvider`, `CalendarProvider`,
`DeveloperModeProvider`, `HomeProvider`, `MessageProvider`,
`OnboardingProvider`) for improved state management.
- Refactor: Updated UI logic in the onboarding screens and settings
pages for better user experience.
- New Feature: Added `AppSnackbar` and `AppDialog` classes for
displaying snackbars and dialogs respectively.
- Refactor: Simplified the `retrievePlugins` function in `plugins.dart`
to always return a list of plugins.
- New Feature: Enhanced logging capabilities with the addition of a
logging statement in `plugins.dart`.
- Bug Fix: Made changes to the notification permissions handling in
`permissions.dart` and `notification_service.dart` for more reliable
notifications.
- Refactor: Utilized the `Provider` package for state management in
  • Loading branch information
mdmohsin7 committed Aug 25, 2024
2 parents 01b4451 + c09f7d5 commit 23a661d
Show file tree
Hide file tree
Showing 37 changed files with 3,190 additions and 2,410 deletions.
2 changes: 2 additions & 0 deletions app/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ linter:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
unnecessary_string_escapes: false
# always_declare_return_types: true
# prefer_const_declarations: true

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
2 changes: 1 addition & 1 deletion app/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1843,4 +1843,4 @@
/* End XCConfigurationList section */
};
rootObject = 97C146E61CF9000F007C117D /* Project object */;
}
}
2 changes: 2 additions & 0 deletions app/lib/backend/http/api/plugins.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:friend_private/backend/http/shared.dart';
Expand All @@ -16,6 +17,7 @@ Future<List<Plugin>> retrievePlugins() async {
);
if (response?.statusCode == 200) {
try {
log('plugins: ${response?.body}');
var plugins = Plugin.fromJsonList(jsonDecode(response!.body));
SharedPreferencesUtil().pluginsList = plugins;
return plugins;
Expand Down
2 changes: 1 addition & 1 deletion app/lib/backend/http/shared.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Future<http.Response?> makeApiCall({
throw Exception('Unsupported HTTP method: $method');
}
} catch (e, stackTrace) {
debugPrint('HTTP request failed: $e');
debugPrint('HTTP request failed: $e, $stackTrace');
CrashReporting.reportHandledCrash(
e,
stackTrace,
Expand Down
3 changes: 2 additions & 1 deletion app/lib/env/env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ abstract class Env {

static String? get mixpanelProjectToken => _instance.mixpanelProjectToken;

static String? get apiBaseUrl => _instance.apiBaseUrl;
// static String? get apiBaseUrl => _instance.apiBaseUrl;

static String? get apiBaseUrl => 'https://based-hardware-development--backened-dev-api.modal.run/';
// static String? get apiBaseUrl => 'https://camel-lucky-reliably.ngrok-free.app/';

static String? get growthbookApiKey => _instance.growthbookApiKey;
Expand Down
33 changes: 32 additions & 1 deletion app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ import 'package:friend_private/firebase_options_prod.dart' as prod;
import 'package:friend_private/flavors.dart';
import 'package:friend_private/pages/home/page.dart';
import 'package:friend_private/pages/onboarding/wrapper.dart';
import 'package:friend_private/providers/auth_provider.dart';
import 'package:friend_private/providers/capture_provider.dart';
import 'package:friend_private/providers/device_provider.dart';
import 'package:friend_private/providers/home_provider.dart';
import 'package:friend_private/providers/memory_provider.dart';
import 'package:friend_private/providers/message_provider.dart';
import 'package:friend_private/providers/onboarding_provider.dart';
import 'package:friend_private/providers/plugin_provider.dart';
import 'package:friend_private/services/notification_service.dart';
import 'package:friend_private/utils/analytics/growthbook.dart';
import 'package:friend_private/utils/analytics/mixpanel.dart';
Expand Down Expand Up @@ -125,6 +132,30 @@ class _MyAppState extends State<MyApp> {
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => AuthenticationProvider()),
// ChangeNotifierProvider(create: (context) => DeviceProvider()),
ChangeNotifierProvider(create: (context) => MemoryProvider()),
ListenableProvider(create: (context) => PluginProvider()),
ChangeNotifierProxyProvider<PluginProvider, MessageProvider>(
create: (context) => MessageProvider(),
update: (BuildContext context, value, MessageProvider? previous) =>
(previous?..updatePluginProvider(value)) ?? MessageProvider(),
),
ChangeNotifierProxyProvider2<MemoryProvider, MessageProvider, CaptureProvider>(
create: (context) => CaptureProvider(),
update: (BuildContext context, memory, message, CaptureProvider? previous) =>
(previous?..updateProviderInstances(memory, message)) ?? CaptureProvider(),
),
ChangeNotifierProxyProvider<CaptureProvider, DeviceProvider>(
create: (context) => DeviceProvider(),
update: (BuildContext context, value, DeviceProvider? previous) =>
(previous?..setProvider(value)) ?? DeviceProvider(),
),
ChangeNotifierProxyProvider<DeviceProvider, OnboardingProvider>(
create: (context) => OnboardingProvider(),
update: (BuildContext context, value, OnboardingProvider? previous) =>
(previous?..setDeviceProvider(value)) ?? OnboardingProvider(),
),
ListenableProvider(create: (context) => HomeProvider()),
],
builder: (context, child) {
Expand Down Expand Up @@ -196,4 +227,4 @@ class _MyAppState extends State<MyApp> {
// ));
// audioSession.setActive(true);
// });
// }
// }
Loading

0 comments on commit 23a661d

Please sign in to comment.