Skip to content

Commit

Permalink
Merge branch 'main' into release/v2.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
WezSieTato authored Mar 11, 2024
2 parents c53029d + 93f4f99 commit 90bbecf
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 32 deletions.
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 47967388dea8945f9f1c1487809851645610dc38

COCOAPODS: 1.12.1
COCOAPODS: 1.15.2
15 changes: 7 additions & 8 deletions lib/models/donate.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import 'package:equatable/equatable.dart';

class Donate extends Equatable {
bool? showButton;
String? url;
String? title;
bool showButton;
String url;
String title;

Donate({required this.showButton, required this.url, required this.title});

Donate.fromJson(Map<String, dynamic> json) {
showButton = json['show_button'];
url = json['url'];
title = json['title'];
}
Donate.fromJson(Map<String, dynamic> json)
: showButton = json['show_button'],
url = json['url'],
title = json['title'];

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
Expand Down
25 changes: 2 additions & 23 deletions lib/pages/scan/companies_list.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:pola_flutter/analytics/pola_analytics.dart';
import 'package:pola_flutter/pages/scan/remote_button.dart';
import 'package:pola_flutter/ui/list_item.dart';
import 'package:url_launcher/url_launcher.dart';
import 'scan_bloc.dart';
Expand Down Expand Up @@ -36,29 +37,7 @@ class CompaniesList extends StatelessWidget {
),
),
),
Padding(
padding:
EdgeInsets.only(left: 8.0, top: 0.0, right: 8.0, bottom: 0.0),
child: TextButton(
style: ButtonStyle(
minimumSize:
MaterialStateProperty.all<Size>(Size(double.infinity, 0)),
backgroundColor: MaterialStateProperty.all<Color>(Colors.red),
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
),
onPressed: () async {
final result = state.list.isNotEmpty ? state.list.first : null;
_analytics
.donateOpened(result?.code ?? "Nie znaleziono produktu");
launchUrl(
Uri.parse(result?.donate?.url ?? "https://www.pola-app.pl"),
mode: LaunchMode.externalApplication,
);
},
child: Text(state.list.isNotEmpty
? state.list.first.donate?.title ?? "Wesprzyj nas!"
: "Wesprzyj nas!"),
))
RemoteButton(RemoteButtonState(state.list.first.donate, state.list.first.code))
]);
}

Expand Down
50 changes: 50 additions & 0 deletions lib/pages/scan/remote_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'package:flutter/material.dart';
import 'package:pola_flutter/analytics/pola_analytics.dart';
import 'package:pola_flutter/models/donate.dart';
import 'package:url_launcher/url_launcher.dart';

class RemoteButtonState {
final Donate? buttonDto;
final String? code;

RemoteButtonState(this.buttonDto, this.code);
}

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

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

@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(
minimumSize:
MaterialStateProperty.all<Size>(Size(double.infinity, 0)),
backgroundColor: MaterialStateProperty.all<Color>(Colors.red),
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
),
onPressed: () async {
_analytics.donateOpened(code);
launchUrl(
url,
mode: LaunchMode.externalApplication,
);
},
child: Text(buttonDto.title),
));
}
}

0 comments on commit 90bbecf

Please sign in to comment.