Skip to content

Commit

Permalink
Share link + Analytics event (#5303)
Browse files Browse the repository at this point in the history
  • Loading branch information
g123k authored May 28, 2024
1 parent 4b6ed1e commit 6274c73
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 14 deletions.
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

0 comments on commit 6274c73

Please sign in to comment.