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

ekran skanowanie guzik dotacji #146

Open
wants to merge 9 commits into
base: feature/redesing
Choose a base branch
from
Open
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: 3 additions & 0 deletions assets/scan/close_small.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 3 additions & 5 deletions lib/pages/scan/companies_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import 'package:pola_flutter/ui/list_item.dart';
import 'dart:math';

class CompaniesList extends StatelessWidget {
CompaniesList(this.state, this.listScrollController);
CompaniesList(this.state, this.listScrollController, this.onCloseRemoteButtonTap);

final ScanState state;
final ScrollController listScrollController;
final GestureTapCallback onCloseRemoteButtonTap;
final PolaAnalytics _analytics = PolaAnalytics.instance();

@override
Expand Down Expand Up @@ -52,10 +53,7 @@ class CompaniesList extends StatelessWidget {
),
),
),
RemoteButton(RemoteButtonState(
state.list.firstOrNull?.donate,
state.list.firstOrNull?.code,
)),
if (state.remoteButtonState != null) RemoteButton(state.remoteButtonState!, onCloseRemoteButtonTap),
],
);
}
Expand Down
81 changes: 47 additions & 34 deletions lib/pages/scan/remote_button.dart
Original file line number Diff line number Diff line change
@@ -1,49 +1,62 @@
import 'package:flutter/material.dart';
import 'package:pola_flutter/analytics/pola_analytics.dart';
import 'package:pola_flutter/models/donate.dart';
import 'package:pola_flutter/theme/assets.gen.dart';
import 'package:pola_flutter/theme/colors.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:equatable/equatable.dart';

class RemoteButtonState {
final Donate? buttonDto;
final String? code;
class RemoteButtonState extends Equatable {
final String title;
final Uri uri;
final String code;

RemoteButtonState(this.buttonDto, this.code);
RemoteButtonState({required this.title, required this.uri, required this.code});

@override
List<Object?> get props => [title, uri, code];
}

class RemoteButton extends StatelessWidget {
RemoteButton(this.state);

final RemoteButtonState state;
final PolaAnalytics _analytics = PolaAnalytics.instance();
final GestureTapCallback onCloseTap;

RemoteButton(this.state, this.onCloseTap);

@override
Widget build(BuildContext context) {
Donate? buttonDto = state.buttonDto;
String? code = state.code;
if (buttonDto == null || buttonDto.showButton == false || code == null) {
return Container();
}
Uri? url = Uri.tryParse(buttonDto.url);
if (url == null) {
return Container();
}

return Padding(
padding: EdgeInsets.only(left: 8.0, top: 0.0, right: 8.0, bottom: 0.0),
child: TextButton(
style: ButtonStyle(
fixedSize: WidgetStateProperty.all<Size>(Size(double.infinity, 0)),
backgroundColor: WidgetStateProperty.all<Color>(Colors.red),
foregroundColor: WidgetStateProperty.all<Color>(Colors.white),
return Container(
width: 328,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nie ustalamy ręcznie szerokości. Ustawiamy odpowiednio paddingi by reszta się sama dopasowała do ekranu.

height: 40,
decoration: BoxDecoration(
color: AppColors.defaultRed,
borderRadius: BorderRadius.circular(25),
),
child: Row(
children: [
Expanded(
child: TextButton(
style: ButtonStyle(
foregroundColor: WidgetStateProperty.all<Color>(Colors.white),
),
onPressed: () async {
PolaAnalytics.instance().donateOpened(state.code);
await launchUrl(
state.uri,
mode: LaunchMode.externalApplication,
);
},
child: Text(state.title),
),
),
Container(
margin: const EdgeInsets.only(right: 8.0),
child: GestureDetector(
onTap: onCloseTap,
child: Assets.scan.closeSmall.svg(),
),
),
onPressed: () async {
_analytics.donateOpened(code);
launchUrl(
url,
mode: LaunchMode.externalApplication,
);
},
child: Text(buttonDto.title),
));
],
),
);
}
}
5 changes: 4 additions & 1 deletion lib/pages/scan/scan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ class _MainPageState extends State<MainPage> {
mainAxisAlignment: MainAxisAlignment.end,
children: [
Expanded(
child: CompaniesList(state, listScrollController)),
child:
CompaniesList(state, listScrollController, () {
_scanBloc.add(ScanEvent.closeRemoteButton());
})),
Column(
children: [
GestureDetector(
Expand Down
24 changes: 23 additions & 1 deletion lib/pages/scan/scan_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:pola_flutter/analytics/pola_analytics.dart';
import 'package:pola_flutter/data/api_response.dart';
import 'package:pola_flutter/data/pola_api_repository.dart';
import 'package:pola_flutter/models/search_result.dart';
import 'package:pola_flutter/pages/scan/remote_button.dart';
import 'package:pola_flutter/pages/scan/scan_event.dart';
import 'package:pola_flutter/pages/scan/scan_state.dart';
import 'package:pola_flutter/pages/scan/scan_vibration.dart';
Expand All @@ -26,6 +27,7 @@ class ScanBloc extends Bloc<ScanEvent, ScanState> {
await _onBarcodeScanned(barcode, emit),
alertDialogDismissed: () => _onAlertDialogDismissed(emit),
torchSwitched: () => _onTorchSwitched(emit),
closeRemoteButton: () => _onCloseRemoteButton(emit),
);
});
}
Expand All @@ -48,7 +50,11 @@ class ScanBloc extends Bloc<ScanEvent, ScanState> {
var results = List<SearchResult>.from(state.list);
results.add(result);
_analytics.searchResultReceived(result);
emit(state.copyWith(list: results, isLoading: false, isError: false));
var remoteButtonState = state.remoteButtonState;
if (remoteButtonState == null && !state.wasRemoteButtonClosed) {
remoteButtonState = result.remoteButton();
}
emit(state.copyWith(list: results, isLoading: false, isError: false, remoteButtonState: remoteButtonState));
} else {
emit(state.copyWith(isLoading: false, isError: true));
}
Expand All @@ -63,4 +69,20 @@ class ScanBloc extends Bloc<ScanEvent, ScanState> {
_onAlertDialogDismissed(Emitter<ScanState> emit) {
emit(state.copyWith(isError: false));
}

_onCloseRemoteButton(Emitter<ScanState> emit) {
emit(state.copyWith(wasRemoteButtonClosed: true, remoteButtonState: null));
}
}

extension on SearchResult {
RemoteButtonState? remoteButton() {
final donate = this.donate;
final code = this.code;
if (code != null && donate != null && donate.showButton) {
final uri = Uri.parse(donate.url);
return RemoteButtonState(title: donate.title, uri: uri, code: code);
}
return null;
}
}
1 change: 1 addition & 0 deletions lib/pages/scan/scan_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ class ScanEvent with _$ScanEvent {
const factory ScanEvent.barcodeScanned(String barcode) = BarcodeScanned;
const factory ScanEvent.alertDialogDismissed() = AlertDialogDismissed;
const factory ScanEvent.torchSwitched() = TorchSwitched;
const factory ScanEvent.closeRemoteButton() = CloseRemoteButton;
}
Loading
Loading