From 82e4c923e7b4ea843346b26530110186634ea4c1 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Fri, 16 Aug 2024 23:08:05 +0800 Subject: [PATCH] :chart_with_upwards_trend: Simple log user share --- lib/widgets/posts/post_action.dart | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/widgets/posts/post_action.dart b/lib/widgets/posts/post_action.dart index b8899f7..a13a086 100644 --- a/lib/widgets/posts/post_action.dart +++ b/lib/widgets/posts/post_action.dart @@ -1,5 +1,6 @@ import 'dart:math'; +import 'package:firebase_analytics/firebase_analytics.dart'; import 'package:flutter/material.dart'; import 'package:flutter_animate/flutter_animate.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -40,9 +41,10 @@ class _PostActionState extends State { } Future _doShare({bool noUri = false}) async { + ShareResult result; final box = context.findRenderObject() as RenderBox?; if ((PlatformInfo.isAndroid || PlatformInfo.isIOS) && !noUri) { - await Share.shareUri( + result = await Share.shareUri( Uri.parse('https://solsynth.dev/posts/${widget.item.id}'), sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size, ); @@ -52,7 +54,7 @@ class _PostActionState extends State { widget.item.body['description'], ]; final isExtraNotEmpty = extraContent.any((x) => x != null); - await Share.share( + result = await Share.share( 'postShareContent'.trParams({ 'username': widget.item.author.nick, 'content': @@ -65,6 +67,14 @@ class _PostActionState extends State { sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size, ); } + + if (result.status != ShareResultStatus.dismissed) { + await FirebaseAnalytics.instance.logShare( + contentType: 'Post', + itemId: widget.item.id.toString(), + method: result.raw, + ); + } } @override