diff --git a/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/apps_use_screen.dart b/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/apps_use_screen.dart index 9691ed86..7202f600 100644 --- a/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/apps_use_screen.dart +++ b/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/apps_use_screen.dart @@ -1,31 +1,30 @@ -import 'package:design_system/design_system.dart'; +import 'package:device_management/src/core/presentation/widgets/time_range_selector.dart'; +import 'package:device_management/src/features/apps_use/presentation/providers/apps_use_controller.dart'; +import 'package:device_management/src/features/apps_use/presentation/widgets/daily_app_usage_section.dart'; +import 'package:device_management/src/features/apps_use/presentation/widgets/top_apps_section.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:legacy_ui/legacy_ui.dart'; import 'package:sf_localizations/sf_localizations.dart'; +import 'package:sf_shared/sf_shared.dart'; import 'package:utils/utils.dart'; -import '../../../core/presentation/widgets/time_range_selector.dart'; -import 'state/apps_use_view_model.dart'; -import 'widgets/daily_app_usage_section.dart'; -import 'widgets/top_apps_section.dart'; - class AppsUseScreen extends ConsumerWidget { const AppsUseScreen({super.key}); @override Widget build(BuildContext context, WidgetRef ref) { - final state = ref.watch(appsUseViewModelProvider); - final vm = ref.read(appsUseViewModelProvider.notifier); + final state = ref.watch(appsUseControllerProvider); + final notifier = ref.read(appsUseControllerProvider.notifier); - ref.listen(appsUseViewModelProvider.select((s) => s.errorMessage), ( - previous, - next, - ) { - if (next.isNotEmpty) { - showTopSnackbar(context, message: next, type: MessageType.error); - } - }); + ref.listen( + appsUseControllerProvider.select((s) => s.errorMessage), + (_, next) async { + if (next.isEmpty) return; + await showErrorDialog(context, I18n.errorGeneric); + notifier.clearError(); + }, + ); return LegacyPageLayout( title: context.translate(I18n.appsUse), @@ -37,24 +36,27 @@ class AppsUseScreen extends ConsumerWidget { children: [ TimeRangeSelector( selected: state.timeRange, - onSelected: (range) => vm.selectTimeRange(range), - onCustomTap: () => _pickCustomRange(context, vm), + onSelected: notifier.selectTimeRange, + onCustomTap: () => _pickCustomRange(context, notifier), ), SizedBox(height: SizeUtils.getByScreen(small: 8, big: 6)), if (state.dailyData.isEmpty) Padding( padding: EdgeInsets.symmetric( vertical: SizeUtils.getByScreen(small: 48, big: 40), - horizontal: SizeUtils.getByScreen(small: 16, big: 14), + horizontal: + SizeUtils.getByScreen(small: 16, big: 14), ), child: Center( child: Text( context.translate(I18n.noAppUsageData), style: TextStyle( - fontSize: SizeUtils.getByScreen(small: 15, big: 14), - color: Theme.of( - context, - ).colorScheme.onSurface.withValues(alpha: 0.5), + fontSize: + SizeUtils.getByScreen(small: 15, big: 14), + color: Theme.of(context) + .colorScheme + .onSurface + .withValues(alpha: 0.5), ), textAlign: TextAlign.center, ), @@ -70,7 +72,7 @@ class AppsUseScreen extends ConsumerWidget { items: state.dailyData, hasMore: state.hasMore, isLoadingMore: state.isLoadingMore, - onLoadMore: () => vm.loadMore(), + onLoadMore: notifier.loadMore, ), ], SizedBox(height: SizeUtils.getByScreen(small: 24, big: 20)), @@ -82,7 +84,7 @@ class AppsUseScreen extends ConsumerWidget { Future _pickCustomRange( BuildContext context, - AppsUseViewModel vm, + AppsUseController notifier, ) async { final now = DateTime.now(); final picked = await showDateRangePicker( @@ -91,7 +93,7 @@ class AppsUseScreen extends ConsumerWidget { lastDate: now, ); if (picked != null) { - vm.selectCustomRange(picked.start, picked.end); + notifier.selectCustomRange(picked.start, picked.end); } } } diff --git a/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/state/apps_use_view_model.dart b/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/providers/apps_use_controller.dart similarity index 68% rename from modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/state/apps_use_view_model.dart rename to modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/providers/apps_use_controller.dart index 3e9bd048..b926ddd2 100644 --- a/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/state/apps_use_view_model.dart +++ b/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/providers/apps_use_controller.dart @@ -1,36 +1,29 @@ import 'dart:async'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:device_management/src/core/data/datasources/health_query_builder.dart'; +import 'package:device_management/src/core/domain/entities/app_usage_time_entity.dart'; +import 'package:device_management/src/core/presentation/time_range.dart'; +import 'package:device_management/src/core/providers/app_usage_times_repository_provider.dart'; +import 'package:device_management/src/features/apps_use/presentation/providers/apps_use_state.dart'; +import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:sf_shared/sf_shared.dart'; import 'package:sf_tracking/sf_tracking.dart'; -import '../../../../core/data/datasources/health_query_builder.dart'; -import '../../../../core/domain/entities/app_usage_time_entity.dart'; -import '../../../../core/domain/repositories/app_usage_times_repository.dart'; -import '../../../../core/presentation/time_range.dart'; -import '../../../../core/providers/app_usage_times_repository_provider.dart'; -import 'apps_use_view_state.dart'; +part 'apps_use_controller.g.dart'; -final appsUseViewModelProvider = - NotifierProvider.autoDispose( - AppsUseViewModel.new, - ); - -class AppsUseViewModel extends Notifier { - late final AppUsageTimesRepository _repository; - late final SfTrackingRepository _tracking; - - static const int _pageSize = 20; +const int _pageSize = 20; +const String _timeField = 'createdAt'; +@riverpod +class AppsUseController extends _$AppsUseController { @override - AppsUseViewState build() { - _repository = ref.read(appUsageTimesRepositoryProvider); - _tracking = ref.read(sfTrackingProvider); + AppsUseState build() { Future.microtask(_init); - return const AppsUseViewState(); + return const AppsUseState(); } - String? get _identificator => ref.read(selectedDeviceProvider).value?.identificator; + String? get _identificator => + ref.read(selectedDeviceProvider).value?.identificator; Future selectTimeRange(TimeRange range) async { if (range == state.timeRange) return; @@ -51,28 +44,23 @@ class AppsUseViewModel extends Notifier { } void _fireTimeRangeEvent() { - final topAppName = state.topApps.isNotEmpty ? state.topApps.first.name : ''; + final topAppName = + state.topApps.isNotEmpty ? state.topApps.first.name : ''; unawaited( - _tracking.legacyDeviceAppsUseTimeRangeChanged( - range: _timeRangeName(state.timeRange), - totalDurationSeconds: state.totalDuration, - topAppName: topAppName, - ), + ref.read(sfTrackingProvider).legacyDeviceAppsUseTimeRangeChanged( + range: _timeRangeName(state.timeRange), + totalDurationSeconds: state.totalDuration, + topAppName: topAppName, + ), ); } - String _timeRangeName(TimeRange range) { - switch (range) { - case TimeRange.today: - return 'today'; - case TimeRange.sevenDays: - return 'seven_days'; - case TimeRange.thirtyDays: - return 'thirty_days'; - case TimeRange.custom: - return 'custom'; - } - } + String _timeRangeName(TimeRange range) => switch (range) { + TimeRange.today => 'today', + TimeRange.sevenDays => 'seven_days', + TimeRange.thirtyDays => 'thirty_days', + TimeRange.custom => 'custom', + }; Future loadMore() async { if (state.isLoadingMore || !state.hasMore) return; @@ -85,16 +73,17 @@ class AppsUseViewModel extends Notifier { final nextPage = state.currentPage + 1; final filters = _buildTimeFilters(); - final items = await _repository.getAppUsageTimes( - identificator: identificator, - queryParameters: HealthQueryBuilder.build( - orderDirection: OrderDirection.desc, - orderField: _timeField, - page: nextPage, - pageSize: _pageSize, - filters: filters, - ), - ); + final items = + await ref.read(appUsageTimesRepositoryProvider).getAppUsageTimes( + identificator: identificator, + queryParameters: HealthQueryBuilder.build( + orderDirection: OrderDirection.desc, + orderField: _timeField, + page: nextPage, + pageSize: _pageSize, + filters: filters, + ), + ); if (!ref.mounted) return; final newDaily = _groupByDay(items); @@ -121,7 +110,6 @@ class AppsUseViewModel extends Notifier { state = state.copyWith(isLoading: false); return; } - await _loadData(); } @@ -135,21 +123,23 @@ class AppsUseViewModel extends Notifier { try { final filters = _buildTimeFilters(); - final items = await _repository.getAppUsageTimes( - identificator: identificator, - queryParameters: HealthQueryBuilder.build( - orderDirection: OrderDirection.desc, - orderField: _timeField, - page: 1, - pageSize: _pageSize, - filters: filters, - ), - ); + final items = + await ref.read(appUsageTimesRepositoryProvider).getAppUsageTimes( + identificator: identificator, + queryParameters: HealthQueryBuilder.build( + orderDirection: OrderDirection.desc, + orderField: _timeField, + page: 1, + pageSize: _pageSize, + filters: filters, + ), + ); if (!ref.mounted) return; final dailyData = _groupByDay(items); final topApps = _computeTopApps(items); - final totalDuration = items.fold(0, (sum, item) => sum + item.duration); + final totalDuration = + items.fold(0, (sum, item) => sum + item.duration); state = state.copyWith( dailyData: dailyData, @@ -162,7 +152,8 @@ class AppsUseViewModel extends Notifier { ); } catch (e) { if (!ref.mounted) return; - state = state.copyWith(isLoading: false, errorMessage: _formatError(e)); + state = + state.copyWith(isLoading: false, errorMessage: _formatError(e)); } } @@ -229,17 +220,17 @@ class AppsUseViewModel extends Notifier { }; for (final d in newItems) { - final existing = merged[d.date]; - if (existing != null) { + final prev = merged[d.date]; + if (prev != null) { final appMap = { - for (final a in existing.apps) a.uid: a, + for (final a in prev.apps) a.uid: a, }; for (final a in d.apps) { - final prev = appMap[a.uid]; + final prevApp = appMap[a.uid]; appMap[a.uid] = AppUsageSummary( uid: a.uid, name: a.name, - totalDuration: (prev?.totalDuration ?? 0) + a.totalDuration, + totalDuration: (prevApp?.totalDuration ?? 0) + a.totalDuration, ); } final apps = appMap.values.toList() @@ -260,8 +251,6 @@ class AppsUseViewModel extends Notifier { return sorted.map((e) => e.value).toList(); } - static const String _timeField = 'createdAt'; - List? _buildTimeFilters() { final range = _getTimeRange(); if (range == null) return null; @@ -297,4 +286,9 @@ class AppsUseViewModel extends Notifier { final msg = e.toString(); return msg.startsWith('Exception: ') ? msg.substring(11) : msg; } + + void clearError() { + if (state.errorMessage.isEmpty) return; + state = state.copyWith(errorMessage: ''); + } } diff --git a/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/providers/apps_use_controller.g.dart b/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/providers/apps_use_controller.g.dart new file mode 100644 index 00000000..c94aa8ed --- /dev/null +++ b/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/providers/apps_use_controller.g.dart @@ -0,0 +1,63 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'apps_use_controller.dart'; + +// ************************************************************************** +// RiverpodGenerator +// ************************************************************************** + +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint, type=warning + +@ProviderFor(AppsUseController) +const appsUseControllerProvider = AppsUseControllerProvider._(); + +final class AppsUseControllerProvider + extends $NotifierProvider { + const AppsUseControllerProvider._() + : super( + from: null, + argument: null, + retry: null, + name: r'appsUseControllerProvider', + isAutoDispose: true, + dependencies: null, + $allTransitiveDependencies: null, + ); + + @override + String debugGetCreateSourceHash() => _$appsUseControllerHash(); + + @$internal + @override + AppsUseController create() => AppsUseController(); + + /// {@macro riverpod.override_with_value} + Override overrideWithValue(AppsUseState value) { + return $ProviderOverride( + origin: this, + providerOverride: $SyncValueProvider(value), + ); + } +} + +String _$appsUseControllerHash() => r'774e7c93e887cec790a95cefa53592bbfbcb035b'; + +abstract class _$AppsUseController extends $Notifier { + AppsUseState build(); + @$mustCallSuper + @override + void runBuild() { + final created = build(); + final ref = this.ref as $Ref; + final element = + ref.element + as $ClassProviderElement< + AnyNotifier, + AppsUseState, + Object?, + Object? + >; + element.handleValue(ref, created); + } +} diff --git a/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/state/apps_use_view_state.dart b/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/providers/apps_use_state.dart similarity index 80% rename from modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/state/apps_use_view_state.dart rename to modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/providers/apps_use_state.dart index 10865251..08fbe2ee 100644 --- a/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/state/apps_use_view_state.dart +++ b/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/providers/apps_use_state.dart @@ -1,8 +1,7 @@ +import 'package:device_management/src/core/presentation/time_range.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; -import '../../../../core/presentation/time_range.dart'; - -part 'apps_use_view_state.freezed.dart'; +part 'apps_use_state.freezed.dart'; @freezed abstract class DailyAppUsage with _$DailyAppUsage { @@ -23,8 +22,8 @@ abstract class AppUsageSummary with _$AppUsageSummary { } @freezed -abstract class AppsUseViewState with _$AppsUseViewState { - const factory AppsUseViewState({ +abstract class AppsUseState with _$AppsUseState { + const factory AppsUseState({ @Default([]) List dailyData, @Default([]) List topApps, @Default(0) int totalDuration, @@ -36,5 +35,5 @@ abstract class AppsUseViewState with _$AppsUseViewState { @Default(true) bool isLoading, @Default(false) bool isLoadingMore, @Default('') String errorMessage, - }) = _AppsUseViewState; + }) = _AppsUseState; } diff --git a/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/state/apps_use_view_state.freezed.dart b/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/providers/apps_use_state.freezed.dart similarity index 84% rename from modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/state/apps_use_view_state.freezed.dart rename to modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/providers/apps_use_state.freezed.dart index c46a38c5..49f32f08 100644 --- a/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/state/apps_use_view_state.freezed.dart +++ b/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/providers/apps_use_state.freezed.dart @@ -3,7 +3,7 @@ // ignore_for_file: type=lint // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark -part of 'apps_use_view_state.dart'; +part of 'apps_use_state.dart'; // ************************************************************************** // FreezedGenerator @@ -544,20 +544,20 @@ as int, } /// @nodoc -mixin _$AppsUseViewState { +mixin _$AppsUseState { List get dailyData; List get topApps; int get totalDuration; int get currentPage; bool get hasMore; TimeRange get timeRange; DateTime? get customStart; DateTime? get customEnd; bool get isLoading; bool get isLoadingMore; String get errorMessage; -/// Create a copy of AppsUseViewState +/// Create a copy of AppsUseState /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) @pragma('vm:prefer-inline') -$AppsUseViewStateCopyWith get copyWith => _$AppsUseViewStateCopyWithImpl(this as AppsUseViewState, _$identity); +$AppsUseStateCopyWith get copyWith => _$AppsUseStateCopyWithImpl(this as AppsUseState, _$identity); @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is AppsUseViewState&&const DeepCollectionEquality().equals(other.dailyData, dailyData)&&const DeepCollectionEquality().equals(other.topApps, topApps)&&(identical(other.totalDuration, totalDuration) || other.totalDuration == totalDuration)&&(identical(other.currentPage, currentPage) || other.currentPage == currentPage)&&(identical(other.hasMore, hasMore) || other.hasMore == hasMore)&&(identical(other.timeRange, timeRange) || other.timeRange == timeRange)&&(identical(other.customStart, customStart) || other.customStart == customStart)&&(identical(other.customEnd, customEnd) || other.customEnd == customEnd)&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.isLoadingMore, isLoadingMore) || other.isLoadingMore == isLoadingMore)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is AppsUseState&&const DeepCollectionEquality().equals(other.dailyData, dailyData)&&const DeepCollectionEquality().equals(other.topApps, topApps)&&(identical(other.totalDuration, totalDuration) || other.totalDuration == totalDuration)&&(identical(other.currentPage, currentPage) || other.currentPage == currentPage)&&(identical(other.hasMore, hasMore) || other.hasMore == hasMore)&&(identical(other.timeRange, timeRange) || other.timeRange == timeRange)&&(identical(other.customStart, customStart) || other.customStart == customStart)&&(identical(other.customEnd, customEnd) || other.customEnd == customEnd)&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.isLoadingMore, isLoadingMore) || other.isLoadingMore == isLoadingMore)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage)); } @@ -566,15 +566,15 @@ int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash( @override String toString() { - return 'AppsUseViewState(dailyData: $dailyData, topApps: $topApps, totalDuration: $totalDuration, currentPage: $currentPage, hasMore: $hasMore, timeRange: $timeRange, customStart: $customStart, customEnd: $customEnd, isLoading: $isLoading, isLoadingMore: $isLoadingMore, errorMessage: $errorMessage)'; + return 'AppsUseState(dailyData: $dailyData, topApps: $topApps, totalDuration: $totalDuration, currentPage: $currentPage, hasMore: $hasMore, timeRange: $timeRange, customStart: $customStart, customEnd: $customEnd, isLoading: $isLoading, isLoadingMore: $isLoadingMore, errorMessage: $errorMessage)'; } } /// @nodoc -abstract mixin class $AppsUseViewStateCopyWith<$Res> { - factory $AppsUseViewStateCopyWith(AppsUseViewState value, $Res Function(AppsUseViewState) _then) = _$AppsUseViewStateCopyWithImpl; +abstract mixin class $AppsUseStateCopyWith<$Res> { + factory $AppsUseStateCopyWith(AppsUseState value, $Res Function(AppsUseState) _then) = _$AppsUseStateCopyWithImpl; @useResult $Res call({ List dailyData, List topApps, int totalDuration, int currentPage, bool hasMore, TimeRange timeRange, DateTime? customStart, DateTime? customEnd, bool isLoading, bool isLoadingMore, String errorMessage @@ -585,14 +585,14 @@ $Res call({ } /// @nodoc -class _$AppsUseViewStateCopyWithImpl<$Res> - implements $AppsUseViewStateCopyWith<$Res> { - _$AppsUseViewStateCopyWithImpl(this._self, this._then); +class _$AppsUseStateCopyWithImpl<$Res> + implements $AppsUseStateCopyWith<$Res> { + _$AppsUseStateCopyWithImpl(this._self, this._then); - final AppsUseViewState _self; - final $Res Function(AppsUseViewState) _then; + final AppsUseState _self; + final $Res Function(AppsUseState) _then; -/// Create a copy of AppsUseViewState +/// Create a copy of AppsUseState /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({Object? dailyData = null,Object? topApps = null,Object? totalDuration = null,Object? currentPage = null,Object? hasMore = null,Object? timeRange = null,Object? customStart = freezed,Object? customEnd = freezed,Object? isLoading = null,Object? isLoadingMore = null,Object? errorMessage = null,}) { return _then(_self.copyWith( @@ -614,8 +614,8 @@ as String, } -/// Adds pattern-matching-related methods to [AppsUseViewState]. -extension AppsUseViewStatePatterns on AppsUseViewState { +/// Adds pattern-matching-related methods to [AppsUseState]. +extension AppsUseStatePatterns on AppsUseState { /// A variant of `map` that fallback to returning `orElse`. /// /// It is equivalent to doing: @@ -628,10 +628,10 @@ extension AppsUseViewStatePatterns on AppsUseViewState { /// } /// ``` -@optionalTypeArgs TResult maybeMap(TResult Function( _AppsUseViewState value)? $default,{required TResult orElse(),}){ +@optionalTypeArgs TResult maybeMap(TResult Function( _AppsUseState value)? $default,{required TResult orElse(),}){ final _that = this; switch (_that) { -case _AppsUseViewState() when $default != null: +case _AppsUseState() when $default != null: return $default(_that);case _: return orElse(); @@ -650,10 +650,10 @@ return $default(_that);case _: /// } /// ``` -@optionalTypeArgs TResult map(TResult Function( _AppsUseViewState value) $default,){ +@optionalTypeArgs TResult map(TResult Function( _AppsUseState value) $default,){ final _that = this; switch (_that) { -case _AppsUseViewState(): +case _AppsUseState(): return $default(_that);case _: throw StateError('Unexpected subclass'); @@ -671,10 +671,10 @@ return $default(_that);case _: /// } /// ``` -@optionalTypeArgs TResult? mapOrNull(TResult? Function( _AppsUseViewState value)? $default,){ +@optionalTypeArgs TResult? mapOrNull(TResult? Function( _AppsUseState value)? $default,){ final _that = this; switch (_that) { -case _AppsUseViewState() when $default != null: +case _AppsUseState() when $default != null: return $default(_that);case _: return null; @@ -694,7 +694,7 @@ return $default(_that);case _: @optionalTypeArgs TResult maybeWhen(TResult Function( List dailyData, List topApps, int totalDuration, int currentPage, bool hasMore, TimeRange timeRange, DateTime? customStart, DateTime? customEnd, bool isLoading, bool isLoadingMore, String errorMessage)? $default,{required TResult orElse(),}) {final _that = this; switch (_that) { -case _AppsUseViewState() when $default != null: +case _AppsUseState() when $default != null: return $default(_that.dailyData,_that.topApps,_that.totalDuration,_that.currentPage,_that.hasMore,_that.timeRange,_that.customStart,_that.customEnd,_that.isLoading,_that.isLoadingMore,_that.errorMessage);case _: return orElse(); @@ -715,7 +715,7 @@ return $default(_that.dailyData,_that.topApps,_that.totalDuration,_that.currentP @optionalTypeArgs TResult when(TResult Function( List dailyData, List topApps, int totalDuration, int currentPage, bool hasMore, TimeRange timeRange, DateTime? customStart, DateTime? customEnd, bool isLoading, bool isLoadingMore, String errorMessage) $default,) {final _that = this; switch (_that) { -case _AppsUseViewState(): +case _AppsUseState(): return $default(_that.dailyData,_that.topApps,_that.totalDuration,_that.currentPage,_that.hasMore,_that.timeRange,_that.customStart,_that.customEnd,_that.isLoading,_that.isLoadingMore,_that.errorMessage);case _: throw StateError('Unexpected subclass'); @@ -735,7 +735,7 @@ return $default(_that.dailyData,_that.topApps,_that.totalDuration,_that.currentP @optionalTypeArgs TResult? whenOrNull(TResult? Function( List dailyData, List topApps, int totalDuration, int currentPage, bool hasMore, TimeRange timeRange, DateTime? customStart, DateTime? customEnd, bool isLoading, bool isLoadingMore, String errorMessage)? $default,) {final _that = this; switch (_that) { -case _AppsUseViewState() when $default != null: +case _AppsUseState() when $default != null: return $default(_that.dailyData,_that.topApps,_that.totalDuration,_that.currentPage,_that.hasMore,_that.timeRange,_that.customStart,_that.customEnd,_that.isLoading,_that.isLoadingMore,_that.errorMessage);case _: return null; @@ -747,8 +747,8 @@ return $default(_that.dailyData,_that.topApps,_that.totalDuration,_that.currentP /// @nodoc -class _AppsUseViewState implements AppsUseViewState { - const _AppsUseViewState({final List dailyData = const [], final List topApps = const [], this.totalDuration = 0, this.currentPage = 1, this.hasMore = false, this.timeRange = TimeRange.today, this.customStart, this.customEnd, this.isLoading = true, this.isLoadingMore = false, this.errorMessage = ''}): _dailyData = dailyData,_topApps = topApps; +class _AppsUseState implements AppsUseState { + const _AppsUseState({final List dailyData = const [], final List topApps = const [], this.totalDuration = 0, this.currentPage = 1, this.hasMore = false, this.timeRange = TimeRange.today, this.customStart, this.customEnd, this.isLoading = true, this.isLoadingMore = false, this.errorMessage = ''}): _dailyData = dailyData,_topApps = topApps; final List _dailyData; @@ -775,17 +775,17 @@ class _AppsUseViewState implements AppsUseViewState { @override@JsonKey() final bool isLoadingMore; @override@JsonKey() final String errorMessage; -/// Create a copy of AppsUseViewState +/// Create a copy of AppsUseState /// with the given fields replaced by the non-null parameter values. @override @JsonKey(includeFromJson: false, includeToJson: false) @pragma('vm:prefer-inline') -_$AppsUseViewStateCopyWith<_AppsUseViewState> get copyWith => __$AppsUseViewStateCopyWithImpl<_AppsUseViewState>(this, _$identity); +_$AppsUseStateCopyWith<_AppsUseState> get copyWith => __$AppsUseStateCopyWithImpl<_AppsUseState>(this, _$identity); @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is _AppsUseViewState&&const DeepCollectionEquality().equals(other._dailyData, _dailyData)&&const DeepCollectionEquality().equals(other._topApps, _topApps)&&(identical(other.totalDuration, totalDuration) || other.totalDuration == totalDuration)&&(identical(other.currentPage, currentPage) || other.currentPage == currentPage)&&(identical(other.hasMore, hasMore) || other.hasMore == hasMore)&&(identical(other.timeRange, timeRange) || other.timeRange == timeRange)&&(identical(other.customStart, customStart) || other.customStart == customStart)&&(identical(other.customEnd, customEnd) || other.customEnd == customEnd)&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.isLoadingMore, isLoadingMore) || other.isLoadingMore == isLoadingMore)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is _AppsUseState&&const DeepCollectionEquality().equals(other._dailyData, _dailyData)&&const DeepCollectionEquality().equals(other._topApps, _topApps)&&(identical(other.totalDuration, totalDuration) || other.totalDuration == totalDuration)&&(identical(other.currentPage, currentPage) || other.currentPage == currentPage)&&(identical(other.hasMore, hasMore) || other.hasMore == hasMore)&&(identical(other.timeRange, timeRange) || other.timeRange == timeRange)&&(identical(other.customStart, customStart) || other.customStart == customStart)&&(identical(other.customEnd, customEnd) || other.customEnd == customEnd)&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.isLoadingMore, isLoadingMore) || other.isLoadingMore == isLoadingMore)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage)); } @@ -794,15 +794,15 @@ int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash( @override String toString() { - return 'AppsUseViewState(dailyData: $dailyData, topApps: $topApps, totalDuration: $totalDuration, currentPage: $currentPage, hasMore: $hasMore, timeRange: $timeRange, customStart: $customStart, customEnd: $customEnd, isLoading: $isLoading, isLoadingMore: $isLoadingMore, errorMessage: $errorMessage)'; + return 'AppsUseState(dailyData: $dailyData, topApps: $topApps, totalDuration: $totalDuration, currentPage: $currentPage, hasMore: $hasMore, timeRange: $timeRange, customStart: $customStart, customEnd: $customEnd, isLoading: $isLoading, isLoadingMore: $isLoadingMore, errorMessage: $errorMessage)'; } } /// @nodoc -abstract mixin class _$AppsUseViewStateCopyWith<$Res> implements $AppsUseViewStateCopyWith<$Res> { - factory _$AppsUseViewStateCopyWith(_AppsUseViewState value, $Res Function(_AppsUseViewState) _then) = __$AppsUseViewStateCopyWithImpl; +abstract mixin class _$AppsUseStateCopyWith<$Res> implements $AppsUseStateCopyWith<$Res> { + factory _$AppsUseStateCopyWith(_AppsUseState value, $Res Function(_AppsUseState) _then) = __$AppsUseStateCopyWithImpl; @override @useResult $Res call({ List dailyData, List topApps, int totalDuration, int currentPage, bool hasMore, TimeRange timeRange, DateTime? customStart, DateTime? customEnd, bool isLoading, bool isLoadingMore, String errorMessage @@ -813,17 +813,17 @@ $Res call({ } /// @nodoc -class __$AppsUseViewStateCopyWithImpl<$Res> - implements _$AppsUseViewStateCopyWith<$Res> { - __$AppsUseViewStateCopyWithImpl(this._self, this._then); +class __$AppsUseStateCopyWithImpl<$Res> + implements _$AppsUseStateCopyWith<$Res> { + __$AppsUseStateCopyWithImpl(this._self, this._then); - final _AppsUseViewState _self; - final $Res Function(_AppsUseViewState) _then; + final _AppsUseState _self; + final $Res Function(_AppsUseState) _then; -/// Create a copy of AppsUseViewState +/// Create a copy of AppsUseState /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') $Res call({Object? dailyData = null,Object? topApps = null,Object? totalDuration = null,Object? currentPage = null,Object? hasMore = null,Object? timeRange = null,Object? customStart = freezed,Object? customEnd = freezed,Object? isLoading = null,Object? isLoadingMore = null,Object? errorMessage = null,}) { - return _then(_AppsUseViewState( + return _then(_AppsUseState( dailyData: null == dailyData ? _self._dailyData : dailyData // ignore: cast_nullable_to_non_nullable as List,topApps: null == topApps ? _self._topApps : topApps // ignore: cast_nullable_to_non_nullable as List,totalDuration: null == totalDuration ? _self.totalDuration : totalDuration // ignore: cast_nullable_to_non_nullable diff --git a/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/widgets/daily_app_usage_section.dart b/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/widgets/daily_app_usage_section.dart index 342a0bb4..c2ef4481 100644 --- a/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/widgets/daily_app_usage_section.dart +++ b/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/widgets/daily_app_usage_section.dart @@ -5,7 +5,7 @@ import 'package:utils/utils.dart'; import '../../../../core/presentation/format_date.dart'; import '../format_duration.dart'; -import '../state/apps_use_view_state.dart'; +import '../providers/apps_use_state.dart'; class DailyAppUsageSection extends StatelessWidget { final List items; diff --git a/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/widgets/top_apps_section.dart b/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/widgets/top_apps_section.dart index f2ac5e09..a086b511 100644 --- a/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/widgets/top_apps_section.dart +++ b/modules/legacy/modules/device_management/lib/src/features/apps_use/presentation/widgets/top_apps_section.dart @@ -4,7 +4,7 @@ import 'package:sf_localizations/sf_localizations.dart'; import 'package:utils/utils.dart'; import '../format_duration.dart'; -import '../state/apps_use_view_state.dart'; +import '../providers/apps_use_state.dart'; class TopAppsSection extends StatelessWidget { final List apps;