Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error sending package from packages exchange console screen #65

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/data/storages/data_source_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ class DataSourceStorageImpl
@override
Future<Result<DataSourceStorageRemoveError, void>> remove() async {
if (await preferences.remove(kDataSourceKey)) {
await put(const Optional.undefined());
return const Result.value(null);
}

await put(const Optional.undefined());

return const Result.error(DataSourceStorageRemoveError.unknown);
}

Expand Down
25 changes: 22 additions & 3 deletions lib/domain/data_source/blocs/data_source_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,34 @@ class DataSourceCubit extends Cubit<DataSourceState> with ConsumerBlocMixin {
super.onChange(change);
}

@override
Future<void> close() async {
Future<void> disconnect() async {
await disconnectAndDispose();
final result = await dataSourceStorage.remove();
result.when(
error: (error) => onError(error, StackTrace.current),
value: (_) {},
);
}

@visibleForTesting
Future<void> disconnectAndDispose() async {
await state.ds.when(
undefined: () async {},
presented: (p) async {
await p.dataSource.disconnect();
await p.dataSource.disconnect().then((value) {
value.when(
error: (error) => onError(error, StackTrace.current),
value: (_) {},
);
});
await p.dataSource.dispose();
},
);
}

@override
Future<void> close() async {
await disconnectAndDispose();
return super.close();
}
}
6 changes: 5 additions & 1 deletion lib/l10n/arb/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -481,5 +481,9 @@
"closedShortStatusMessage": "Closed",
"openedShortStatusMessage": "Closed",
"decimalShortListTileLabel": "dec",
"windscreenWipersInterfaceTitle": "Wipers"
"windscreenWipersInterfaceTitle": "Wipers",
"noButtonCaption": "No",
"yesButtonCaption": "Yes",
"disconnectButtonCaption": "Disconnect",
"areYouSureYouWantToDisconnectDialogTitle": "Are you sure you want to disconnect?"
}
6 changes: 5 additions & 1 deletion lib/l10n/arb/app_ru.arb
Original file line number Diff line number Diff line change
Expand Up @@ -481,5 +481,9 @@
"closedShortStatusMessage": "Π—Π°ΠΊΡ€",
"openedShortStatusMessage": "ΠžΡ‚ΠΊΡ€",
"decimalShortListTileLabel": "dec",
"windscreenWipersInterfaceTitle": "Π”Π²ΠΎΡ€Π½ΠΈΠΊΠΈ"
"windscreenWipersInterfaceTitle": "Π”Π²ΠΎΡ€Π½ΠΈΠΊΠΈ",
"noButtonCaption": "НСт",
"yesButtonCaption": "Π”Π°",
"disconnectButtonCaption": "ΠžΡ‚ΠΊΠ»ΡŽΡ‡ΠΈΡ‚ΡŒΡΡ",
"areYouSureYouWantToDisconnectDialogTitle": "Π’Ρ‹ ΡƒΠ²Π΅Ρ€Π΅Π½Ρ‹ Ρ‡Ρ‚ΠΎ Ρ…ΠΎΡ‚ΠΈΡ‚Π΅ ΠΎΡ‚ΠΊΠ»ΡŽΡ‡ΠΈΡ‚ΡŒΡΡ?"
}
3 changes: 3 additions & 0 deletions lib/presentation/app/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ class MaterialTheme {
shape: ElevatedButtonBorder(colors: colors),
selectedColor: colors.primaryAccent.withOpacity(.15),
),
badgeTheme: BadgeThemeData(
backgroundColor: colors.primary,
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
elevation: 0,
Expand Down
7 changes: 5 additions & 2 deletions lib/presentation/routes/main_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ import 'package:pixel_app_flutter/presentation/screens/user_defined_buttons/add_
import 'package:pixel_app_flutter/presentation/screens/user_defined_buttons/edit_user_defined_button_screen.dart';
import 'package:pixel_app_flutter/presentation/screens/user_defined_buttons/models/button_builder.dart';
import 'package:pixel_app_flutter/presentation/screens/user_defined_buttons/select_button_type_screen.dart';
import 'package:pixel_app_flutter/presentation/widgets/common/molecules/bool_dialog.dart';

part 'guards/selected_data_source_guard.dart';
part 'main_router.gr.dart';
part 'subroutes/developer_tools_route.dart';
part 'subroutes/home_route.dart';
part 'subroutes/select_data_source_route.dart';
part 'subroutes/settings_route.dart';
part 'subroutes/user_defined_buttons_route.dart';
part 'guards/selected_data_source_guard.dart';

@AutoRouterConfig(
replaceInRouteName: 'ScreenWrapper|Screen|PageWrapper|Page|Scope,Route',
Expand Down Expand Up @@ -75,12 +76,14 @@ class MainRouter extends _$MainRouter {
_selectDataSourceRoute(root: false),
//
_userDefinedButtonsRoute,
//
_developerToolsRoute(),
],
),
//
_selectDataSourceRoute(),
//
_developerToolsRoute,
_developerToolsRoute(selectedDS: false),
//
CustomRoute(
path: '/loading',
Expand Down
111 changes: 56 additions & 55 deletions lib/presentation/routes/subroutes/developer_tools_route.dart
Original file line number Diff line number Diff line change
@@ -1,79 +1,80 @@
part of '../main_router.dart';

final _developerToolsRoute = AutoRoute(
path: '/developer-tools',
page: DeveloperToolsFlow.page,
children: [
AutoRoute(
path: '',
page: DeveloperToolsRoute.page,
),
AutoRoute(
path: 'packages-exchange-console',
page: PackagesExchangeConsoleRoute.page,
),
AutoRoute(
path: 'exchange-logs',
page: RequestsExchangeLogsFlow.page,
AutoRoute _developerToolsRoute({bool selectedDS = true}) => AutoRoute(
path: '${selectedDS ? '' : '/'}developer-tools',
page: DeveloperToolsFlow.page,
children: [
AutoRoute(
page: RequestsExchangeLogsRoute.page,
initial: true,
path: '',
page: DeveloperToolsRoute.page,
),
if (selectedDS)
AutoRoute(
path: 'packages-exchange-console',
page: PackagesExchangeConsoleRoute.page,
),
AutoRoute(
path: 'exchange-logs',
page: RequestsExchangeLogsFlow.page,
children: [
AutoRoute(
path: 'processed',
page: ProcessedExchangeLogsRoute.page,
),
AutoRoute(
path: 'raw',
page: RawExchangeLogsRoute.page,
page: RequestsExchangeLogsRoute.page,
initial: true,
children: [
AutoRoute(
path: 'processed',
page: ProcessedExchangeLogsRoute.page,
),
AutoRoute(
path: 'raw',
page: RawExchangeLogsRoute.page,
),
],
),
],
),
],
),
AutoRoute(
path: 'filter',
page: RequestsExchangeLogsFilterFlow.page,
children: [
AutoRoute(
initial: true,
page: RequestsExchangeLogsFilterRoute.page,
path: 'filter',
page: RequestsExchangeLogsFilterFlow.page,
children: [
AutoRoute(
initial: true,
page: RequestsExchangeLogsFilterRoute.page,
),
CustomRoute(
page: FilterParameterIdDialogRoute.page,
path: 'parameter-id',
customRouteBuilder: dialogRouteBuilder,
),
CustomRoute(
page: FilterRequestTypeDialogRoute.page,
path: 'request-type',
customRouteBuilder: dialogRouteBuilder,
),
CustomRoute(
page: FilterDirectionDialogRoute.page,
path: 'direction',
customRouteBuilder: dialogRouteBuilder,
),
],
),
CustomRoute(
page: FilterParameterIdDialogRoute.page,
path: 'parameter-id',
page: ChangeParametersSubscriptionDialogRoute.page,
path: 'change-parameters-subscription',
customRouteBuilder: dialogRouteBuilder,
),
CustomRoute(
page: FilterRequestTypeDialogRoute.page,
path: 'request-type',
page: ChangeRequestPeriodDialogRoute.page,
path: 'change-request-period',
customRouteBuilder: dialogRouteBuilder,
),
CustomRoute(
page: FilterDirectionDialogRoute.page,
path: 'direction',
page: ChangeHandshakeResponseTimeoutDialogRoute.page,
path: 'change-handshake-response-timeout',
customRouteBuilder: dialogRouteBuilder,
),
],
),
CustomRoute(
page: ChangeParametersSubscriptionDialogRoute.page,
path: 'change-parameters-subscription',
customRouteBuilder: dialogRouteBuilder,
),
CustomRoute(
page: ChangeRequestPeriodDialogRoute.page,
path: 'change-request-period',
customRouteBuilder: dialogRouteBuilder,
),
CustomRoute(
page: ChangeHandshakeResponseTimeoutDialogRoute.page,
path: 'change-handshake-response-timeout',
customRouteBuilder: dialogRouteBuilder,
),
],
);
);

@RoutePage(name: 'RequestsExchangeLogsFlow')
class RequestsExchangeLogsScope extends AutoRouter {
Expand Down
14 changes: 14 additions & 0 deletions lib/presentation/routes/subroutes/select_data_source_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ AutoRoute _selectDataSourceRoute({bool root = true}) => AutoRoute(
path: 'select-device',
customRouteBuilder: dialogRouteBuilder,
),
CustomRoute(
page: DataSourceDisconnectDialogRoute.page,
path: 'disconnect',
customRouteBuilder: dialogRouteBuilder,
),
],
),
CustomRoute(
Expand All @@ -40,3 +45,12 @@ AutoRoute _selectDataSourceRoute({bool root = true}) => AutoRoute(
class SelectDataSourceGeneralScope extends AutoRouter {
const SelectDataSourceGeneralScope({super.key});
}

@RoutePage<bool>(name: 'DataSourceDisconnectDialogRoute')
class DataSourceDisconnectDialog extends BoolDialog {
const DataSourceDisconnectDialog({
super.key,
super.content,
required super.title,
});
}
24 changes: 24 additions & 0 deletions lib/presentation/screens/data_source/data_source_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,30 @@ class DataSourceScreen extends StatelessWidget {
screenTitle: currentDataSource != null
? context.l10n.dataSourceScreenTitle
: context.l10n.selectDataSourceScreenTitle,
bottomRight: currentDataSource == null
? null
: GlueTitle(
alignment: Alignment.centerRight,
title: context.l10n.disconnectButtonCaption,
side: GlueTitleSide.bottom,
child: PIconButton(
onPressed: () async {
final disconnect = await context.router.push<bool>(
DataSourceDisconnectDialogRoute(
title: context.l10n
.areYouSureYouWantToDisconnectDialogTitle,
),
) ??
false;
if (!context.mounted) return;
if (disconnect) {
await context.read<DataSourceCubit>().disconnect();
}
},
icon: Icons.logout,
size: PIconButtonSize.normal,
),
),
bottomLeft: showCloseButton
? null
: GlueTitle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,14 @@ class DeveloperToolsScreen extends StatelessWidget {
context.router.push(const RequestsExchangeLogsFlow());
},
),
ListTile(
title: Text(context.l10n.packagesExchangeConsoleScreenTitle),
onTap: () {
context.router.push(const PackagesExchangeConsoleRoute());
},
),
if (context.read<DataSourceCubit>().state.ds.isPresent)
ListTile(
title:
Text(context.l10n.packagesExchangeConsoleScreenTitle),
onTap: () {
context.router.push(const PackagesExchangeConsoleRoute());
},
),
ListTile(
title: Text(context.l10n.exportLogsListTileLabel),
onTap: () async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pixel_app_flutter/domain/data_source/data_source.dart';
import 'package:pixel_app_flutter/domain/developer_tools/developer_tools.dart';
import 'package:pixel_app_flutter/l10n/l10n.dart';
import 'package:pixel_app_flutter/presentation/routes/main_router.dart';
import 'package:pixel_app_flutter/presentation/screens/developer_tools/widgets/exchange_log_card.dart';
import 'package:pixel_app_flutter/presentation/screens/developer_tools/widgets/filter_button.dart';
import 'package:re_widgets/re_widgets.dart';

@RoutePage()
Expand Down Expand Up @@ -40,12 +40,7 @@ class _PackagesExchangeConsoleScreenState
appBar: AppBar(
title: Text(context.l10n.packagesExchangeConsoleScreenTitle),
actions: [
IconButton(
onPressed: () {
context.router.push(const RequestsExchangeLogsFilterFlow());
},
icon: const Icon(Icons.filter_list_alt),
),
const FilterButton(),
BlocBuilder<PauseLogsUpdatingCubit, bool>(
builder: (context, pause) {
return IconButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ class RequestsExchangeLogsFilterScreen extends StatelessWidget {
onPressed: context.router.pop,
),
title: Text(context.l10n.requestsFilterScreenTitle),
actions: [
IconButton(
icon: const Icon(Icons.cleaning_services),
onPressed: () {
context.read<RequestsExchangeLogsFilterCubit>().update(
const RequestsExchangeLogsFilterState(),
);
},
),
],
),
body: BlocBuilder<RequestsExchangeLogsFilterCubit,
RequestsExchangeLogsFilterState>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pixel_app_flutter/domain/developer_tools/developer_tools.dart';
import 'package:pixel_app_flutter/l10n/l10n.dart';
import 'package:pixel_app_flutter/presentation/routes/main_router.dart';
import 'package:pixel_app_flutter/presentation/screens/developer_tools/widgets/filter_button.dart';

@RoutePage()
class RequestsExchangeLogsScreen extends StatelessWidget {
Expand All @@ -24,12 +25,7 @@ class RequestsExchangeLogsScreen extends StatelessWidget {
),
title: Text(context.l10n.requestsExchangeLogsScreenTitle),
actions: [
IconButton(
onPressed: () {
context.router.push(const RequestsExchangeLogsFilterFlow());
},
icon: const Icon(Icons.filter_list_alt),
),
const FilterButton(),
BlocBuilder<PauseLogsUpdatingCubit, bool>(
builder: (context, pause) {
return IconButton(
Expand Down
Loading
Loading