Skip to content

Commit

Permalink
add social share insta background and small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
NeXTormer committed Dec 31, 2023
1 parent 17a34f9 commit f1da64a
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 22 deletions.
Binary file added assets/images/social-share-insta-background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions lib/misc/bottom_sheet.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sheet/route.dart';
import 'package:sheet/sheet.dart';

Future<void> showFredericBottomSheet(
{required BuildContext context,
bool enableDrag = false,
bool isDismissible = false,
required Widget Function(BuildContext) builder}) {
return Navigator.of(context).push(CupertinoSheetRoute<void>(
builder: builder,
));
HapticFeedback.lightImpact();
return Navigator.of(context)
.push(CupertinoSheetRoute<void>(builder: builder));
// Navigator.of(context)
// .push(SheetRoute<void>(builder: builder, draggable: enableDrag));
}
Expand Down
1 change: 1 addition & 0 deletions lib/screens/activity_list_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ActivityListScreen extends StatelessWidget {
child: FredericScaffold(
floatingActionButton: FloatingActionButton(
key: ValueKey<String>('fab_activitylistscreen'),
heroTag: 'fab_activitylistscreen',
onPressed: () {
// if (CupertinoScaffold.of(context) == null) {
if (false) {
Expand Down
1 change: 1 addition & 0 deletions lib/screens/bottom_navigation_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class _BottomNavigationScreenState extends State<BottomNavigationScreen>
type: BottomNavigationBarType.fixed,
currentIndex: currentIndex,
onTap: (index) {
HapticFeedback.selectionClick();
setState(() {
currentIndex = index;
pageController.jumpToPage(index);
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class _HomeScreenState extends State<HomeScreen> {
GoalSegment(),
LastWorkoutSegment(),
ActivityHeatmapChartSegment(),
ProgressChartSegment(),
if (false) ProgressChartSegment(),
MuscleGroupChartSegment(),
WeekVolumeChartSegment(),
AchievementSegment(),
Expand Down
2 changes: 2 additions & 0 deletions lib/screens/workout_list_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class _WorkoutListScreenState extends State<WorkoutListScreen> {
Widget buildAlternativeAddWorkoutButton(BuildContext context) {
return FloatingActionButton(
backgroundColor: theme.mainColor,
heroTag: 'fab_workoutlistscreen',
onPressed: () => showFredericBottomSheet(
context: context,
builder: (c) => Scaffold(
Expand All @@ -74,6 +75,7 @@ class _WorkoutListScreenState extends State<WorkoutListScreen> {
margin: const EdgeInsets.all(16.0),
child: FloatingActionButton(
elevation: 0,
heroTag: 'fab_workoutlistscreen',
highlightElevation: 0,
backgroundColor: theme.mainColor,
onPressed: () => showFredericBottomSheet(
Expand Down
54 changes: 37 additions & 17 deletions lib/widgets/home_screen/last_workout/last_workout_segment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:typed_data';

import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:frederic/main.dart';
import 'package:frederic/widgets/home_screen/last_workout/last_workout_card.dart';
import 'package:frederic/widgets/standard_elements/frederic_action_dialog.dart';
Expand All @@ -23,6 +24,13 @@ class LastWorkoutSegment extends StatefulWidget {
class _LastWorkoutSegmentState extends State<LastWorkoutSegment> {
bool screenshot = false;
ScreenshotController screenshotController = ScreenshotController();
String? imageBackgroundPath;

@override
void initState() {
copyBundleAssets();
super.initState();
}

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -67,8 +75,8 @@ class _LastWorkoutSegmentState extends State<LastWorkoutSegment> {
icon: screenshot
? null
: (Platform.isAndroid
? Icons.share_outlined
: Icons.ios_share),
? Icons.share_outlined
: Icons.ios_share),
onPressed: () => handleShare(context),
),
const SizedBox(height: 8),
Expand All @@ -84,6 +92,19 @@ class _LastWorkoutSegmentState extends State<LastWorkoutSegment> {
);
}

Future<void> copyBundleAssets() async {
imageBackgroundPath = await copyImage('social-share-insta-background.jpg');
}

Future<String> copyImage(String filename) async {
final tempDir = await getTemporaryDirectory();
ByteData bytes = await rootBundle.load("assets/images/$filename");
final assetPath = '${tempDir.path}/$filename';
File file = await File(assetPath).create();
await file.writeAsBytes(bytes.buffer.asUint8List());
return file.path;
}

void handleShare(BuildContext context) async {
setState(() {
screenshot = true;
Expand All @@ -92,9 +113,7 @@ class _LastWorkoutSegmentState extends State<LastWorkoutSegment> {
await Future.delayed(const Duration(milliseconds: 1));

Uint8List? image = await screenshotController.capture(
pixelRatio: MediaQuery
.of(context)
.devicePixelRatio);
pixelRatio: MediaQuery.of(context).devicePixelRatio);

setState(() {
screenshot = false;
Expand All @@ -119,18 +138,19 @@ class _LastWorkoutSegmentState extends State<LastWorkoutSegment> {
children: [
FredericButton(tr('sharing.share_to_instagram_stories'),
onPressed: () async {
final result = await SocialShare.shareInstagramStory(
imagePath:
file.path,
backgroundTopColor:
'#${theme.mainColor.value.toRadixString(16)}',
backgroundBottomColor:
'#${theme.accentColor.value.toRadixString(16)}',
attributionURL: 'https://neverskipfitness.com',
appId: '');
print(result);
Navigator.of(context).pop();
}),
final result = await SocialShare.shareInstagramStory(
imagePath: file.path,
backgroundResourcePath: imageBackgroundPath,
// backgroundTopColor:
// '#${theme.mainColor.value.toRadixString(16)}',
// backgroundBottomColor:
// '#${theme.accentColor.value.toRadixString(16)}',

attributionURL: 'https://neverskipfitness.com',
appId: '');
print(result);
Navigator.of(context).pop();
}),
const SizedBox(height: 8),
FredericButton(tr('sharing.share_to_other'), onPressed: () {
final result = SocialShare.shareOptions(
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/standard_elements/frederic_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FredericButton extends StatelessWidget {
return GestureDetector(
onTap: () {
if (haptics) {
HapticFeedback.selectionClick();
HapticFeedback.mediumImpact();
}
if (!loading) {
onPressed.call();
Expand Down
1 change: 1 addition & 0 deletions lib/widgets/standard_elements/streak_icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class StreakIcon extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Container();
return Container(
padding: EdgeInsets.symmetric(horizontal: 2, vertical: 4),
child: Row(
Expand Down
2 changes: 2 additions & 0 deletions lib/widgets/workout_list_screen/workout_card.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:frederic/backend/backend.dart';
import 'package:frederic/main.dart';
import 'package:frederic/screens/edit_workout_screen.dart';
Expand Down Expand Up @@ -59,6 +60,7 @@ class _WorkoutCardState extends State<WorkoutCard> {
onLongPress: () => handleLongPress(context),
onTap: widget.clickable
? () {
HapticFeedback.selectionClick();
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => EditWorkoutScreen(
widget.workout.id,
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ flutter:
- assets/translations/
- assets/images/credits/felix.jpg
- assets/images/credits/stefan.jpg
- assets/images/social-share-insta-background.jpg

fonts:
- family: ExtraIcons
Expand Down

0 comments on commit f1da64a

Please sign in to comment.