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

feat: NutriScore guide with working Share button + Analytics events #5303

Merged
merged 1 commit into from
May 28, 2024
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
8 changes: 1 addition & 7 deletions packages/smooth_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:io';

import 'package:app_store_shared/app_store_shared.dart';
import 'package:dart_ping_ios/dart_ping_ios.dart';
import 'package:device_preview/device_preview.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -85,12 +84,7 @@ Future<void> launchSmoothApp({
await AnalyticsHelper.initSentry(
appRunner: () => runApp(const SmoothApp()));
} else {
runApp(
DevicePreview(
enabled: true,
builder: (_) => const SmoothApp(),
),
);
runApp(const SmoothApp());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@ class GuideNutriscoreV2 extends StatelessWidget {

@override
Widget build(BuildContext context) {
return const GuidesPage(
header: _NutriscoreHeader(),
body: <Widget>[
return GuidesPage(
pageName: 'NutriscoreV2',
header: const _NutriscoreHeader(),
body: const <Widget>[
_NutriScoreSection1(),
_NutriScoreSection2(),
_NutriScoreSection3(),
_NutriScoreSection4(),
_NutriScoreSection5(),
],
footer: SliverToBoxAdapter(
child: GuidesFooter(),
child: GuidesFooter(
shareMessage: 'guide_nutriscore_v2_share_message'.translation,
shareUrl: 'guide_nutriscore_v2_share_link'.translation,
),
),
);
}
Expand Down
25 changes: 22 additions & 3 deletions packages/smooth_app/lib/pages/guides/helpers/guides_content.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:matomo_tracker/matomo_tracker.dart';
import 'package:provider/provider.dart';
import 'package:sliver_tools/sliver_tools.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
Expand All @@ -15,6 +16,7 @@ class GuidesPage extends StatelessWidget {
const GuidesPage({
required this.header,
required this.body,
required this.pageName,
this.footer,
super.key,
});
Expand All @@ -23,6 +25,9 @@ class GuidesPage extends StatelessWidget {
final List<Widget> body;
final Widget? footer;

// Page name for the Analytics event
final String pageName;

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -33,6 +38,7 @@ class GuidesPage extends StatelessWidget {
builder: (BuildContext context, AsyncSnapshot<void> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return _GuidesPageBody(
pageName: pageName,
slivers: <Widget>[
header,
...body,
Expand All @@ -46,11 +52,21 @@ class GuidesPage extends StatelessWidget {
}
}

class _GuidesPageBody extends StatelessWidget {
_GuidesPageBody({required this.slivers});
class _GuidesPageBody extends StatefulWidget {
const _GuidesPageBody({
required this.slivers,
required this.pageName,
}) : assert(pageName.length > 0);

final List<Widget> slivers;
final String pageName;

@override
State<_GuidesPageBody> createState() => _GuidesPageBodyState();
}

class _GuidesPageBodyState extends State<_GuidesPageBody>
with TraceableClientMixin {
final ScrollController _controller = ScrollController();

@override
Expand Down Expand Up @@ -92,11 +108,14 @@ class _GuidesPageBody extends StatelessWidget {
GuidesHeader.HEADER_HEIGHT - kToolbarHeight,
],
),
slivers: slivers,
slivers: widget.slivers,
),
),
);
}

@override
String get actionName => 'Opened ${widget.pageName}';
}

class GuidesParagraph extends StatelessWidget {
Expand Down
32 changes: 26 additions & 6 deletions packages/smooth_app/lib/pages/guides/helpers/guides_footer.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import 'dart:math' as math;

import 'package:flutter/material.dart';
import 'package:share_plus/share_plus.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/helpers/analytics_helper.dart';
import 'package:smooth_app/pages/guides/helpers/guides_translations.dart';
import 'package:smooth_app/themes/smooth_theme_colors.dart';

class GuidesFooter extends StatelessWidget {
const GuidesFooter({super.key});
const GuidesFooter({
required this.shareUrl,
this.shareMessage,
super.key,
});

final String? shareMessage;
final String shareUrl;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -38,20 +48,30 @@ class GuidesFooter extends StatelessWidget {
vertical: VERY_LARGE_SPACE,
),
),
// TODO(g123k): Implement sharing functionality
child: const Text(
'Partager',
style: TextStyle(
child: Text(
'guide_share_label'.translation,
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15.5,
),
),
onPressed: () {},
onPressed: () {
Share.share(_shareText);
AnalyticsHelper.trackOutlink(url: shareUrl);
},
),
),
),
);
}

String get _shareText {
if (shareMessage?.isNotEmpty == true) {
return '$shareMessage\n$shareUrl';
} else {
return shareUrl;
}
}
}

class _FooterPainter extends CustomPainter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class UserPreferencesFaq extends AbstractUserPreferences {
NutriScoreValue.b,
true,
),
onTap: () => Navigator.of(context).push(
onTap: () => Navigator.of(context, rootNavigator: true).push(
MaterialPageRoute<void>(
builder: (BuildContext context) => const GuideNutriscoreV2(),
),
Expand Down
24 changes: 0 additions & 24 deletions packages/smooth_app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.10"
device_frame:
dependency: transitive
description:
name: device_frame
sha256: afe76182aec178d171953d9b4a50a43c57c7cf3c77d8b09a48bf30c8fa04dd9d
url: "https://pub.dev"
source: hosted
version: "1.1.0"
device_info_plus:
dependency: "direct main"
description:
Expand All @@ -430,14 +422,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "7.0.0"
device_preview:
dependency: "direct main"
description:
name: device_preview
sha256: "2f097bf31b929e15e6756dbe0ec1bcb63952ab9ed51c25dc5a2c722d2b21fdaf"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
diacritic:
dependency: "direct main"
description:
Expand Down Expand Up @@ -767,14 +751,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.8.5+3"
freezed_annotation:
dependency: transitive
description:
name: freezed_annotation
sha256: c3fd9336eb55a38cc1bbd79ab17573113a8deccd0ecbbf926cca3c62803b5c2d
url: "https://pub.dev"
source: hosted
version: "2.4.1"
fuchsia_remote_debug_protocol:
dependency: transitive
description: flutter
Expand Down
1 change: 0 additions & 1 deletion packages/smooth_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ dependencies:
barcode_widget: 2.0.4
carousel_slider: 4.2.1
cupertino_icons: 1.0.8
device_preview: 1.1.0
flutter_svg: 2.0.10+1
flutter_map: 6.1.0
html: 0.15.4
Expand Down
Loading