diff --git a/packages/smooth_app/lib/pages/guides/guide/guide_nutriscore_v2.dart b/packages/smooth_app/lib/pages/guides/guide/guide_nutriscore_v2.dart index 1036d512bc6d..638945823d8c 100644 --- a/packages/smooth_app/lib/pages/guides/guide/guide_nutriscore_v2.dart +++ b/packages/smooth_app/lib/pages/guides/guide/guide_nutriscore_v2.dart @@ -11,9 +11,10 @@ class GuideNutriscoreV2 extends StatelessWidget { @override Widget build(BuildContext context) { - return const GuidesPage( - header: _NutriscoreHeader(), - body: [ + return GuidesPage( + pageName: 'NutriscoreV2', + header: const _NutriscoreHeader(), + body: const [ _NutriScoreSection1(), _NutriScoreSection2(), _NutriScoreSection3(), @@ -21,7 +22,10 @@ class GuideNutriscoreV2 extends StatelessWidget { _NutriScoreSection5(), ], footer: SliverToBoxAdapter( - child: GuidesFooter(), + child: GuidesFooter( + shareMessage: 'guide_nutriscore_v2_share_message'.translation, + shareUrl: 'guide_nutriscore_v2_share_link'.translation, + ), ), ); } diff --git a/packages/smooth_app/lib/pages/guides/helpers/guides_content.dart b/packages/smooth_app/lib/pages/guides/helpers/guides_content.dart index de37e4318b5f..73a1a06228cf 100644 --- a/packages/smooth_app/lib/pages/guides/helpers/guides_content.dart +++ b/packages/smooth_app/lib/pages/guides/helpers/guides_content.dart @@ -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'; @@ -15,6 +16,7 @@ class GuidesPage extends StatelessWidget { const GuidesPage({ required this.header, required this.body, + required this.pageName, this.footer, super.key, }); @@ -23,6 +25,9 @@ class GuidesPage extends StatelessWidget { final List body; final Widget? footer; + // Page name for the Analytics event + final String pageName; + @override Widget build(BuildContext context) { return Scaffold( @@ -33,6 +38,7 @@ class GuidesPage extends StatelessWidget { builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { return _GuidesPageBody( + pageName: pageName, slivers: [ header, ...body, @@ -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 slivers; + final String pageName; + + @override + State<_GuidesPageBody> createState() => _GuidesPageBodyState(); +} +class _GuidesPageBodyState extends State<_GuidesPageBody> + with TraceableClientMixin { final ScrollController _controller = ScrollController(); @override @@ -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 { diff --git a/packages/smooth_app/lib/pages/guides/helpers/guides_footer.dart b/packages/smooth_app/lib/pages/guides/helpers/guides_footer.dart index 833ef35b69e0..a7eb31b43f36 100644 --- a/packages/smooth_app/lib/pages/guides/helpers/guides_footer.dart +++ b/packages/smooth_app/lib/pages/guides/helpers/guides_footer.dart @@ -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) { @@ -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 { diff --git a/packages/smooth_app/lib/pages/preferences/user_preferences_faq.dart b/packages/smooth_app/lib/pages/preferences/user_preferences_faq.dart index 1be62fad6a79..a4658059dff7 100644 --- a/packages/smooth_app/lib/pages/preferences/user_preferences_faq.dart +++ b/packages/smooth_app/lib/pages/preferences/user_preferences_faq.dart @@ -71,7 +71,7 @@ class UserPreferencesFaq extends AbstractUserPreferences { NutriScoreValue.b, true, ), - onTap: () => Navigator.of(context).push( + onTap: () => Navigator.of(context, rootNavigator: true).push( MaterialPageRoute( builder: (BuildContext context) => const GuideNutriscoreV2(), ),