OpenContacts/lib/client_holder.dart

37 lines
1.3 KiB
Dart
Raw Normal View History

2023-05-05 06:45:00 -04:00
import 'package:contacts_plus_plus/clients/api_client.dart';
import 'package:contacts_plus_plus/clients/notification_client.dart';
import 'package:contacts_plus_plus/clients/settings_client.dart';
import 'package:contacts_plus_plus/models/authentication_data.dart';
import 'package:flutter/material.dart';
class ClientHolder extends InheritedWidget {
final ApiClient apiClient;
final SettingsClient settingsClient;
final NotificationClient notificationClient = NotificationClient();
ClientHolder({
super.key,
required AuthenticationData authenticationData,
required this.settingsClient,
required super.child,
required Function() onLogout,
}) : apiClient = ApiClient(authenticationData: authenticationData, onLogout: onLogout);
2023-05-05 06:45:00 -04:00
static ClientHolder? maybeOf(BuildContext context) {
return context.dependOnInheritedWidgetOfExactType<ClientHolder>();
}
static ClientHolder of(BuildContext context) {
final ClientHolder? result = maybeOf(context);
assert(result != null, 'No AuthenticatedClient found in context');
return result!;
}
@override
bool updateShouldNotify(covariant ClientHolder oldWidget) =>
oldWidget.apiClient != apiClient
2023-05-25 09:50:38 -04:00
|| oldWidget.settingsClient != settingsClient
|| oldWidget.notificationClient != notificationClient;
2023-05-05 06:45:00 -04:00
}