Skip to content

Commit

Permalink
Merge pull request #79 from trullse/feat/share-suggestion
Browse files Browse the repository at this point in the history
feat: share suggestion
  • Loading branch information
luffan authored Oct 14, 2024
2 parents e6f693e + 2328d3d commit a2d1d5d
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 59 deletions.
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
Expand Down
21 changes: 21 additions & 0 deletions lib/src/presentation/pages/suggestion/suggestion_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ class SuggestionPage extends StatefulWidget {
final Suggestion suggestion;
final OnUploadMultiplePhotosCallback? onUploadMultiplePhotos;
final OnSaveToGalleryCallback? onSaveToGallery;
final OnShareSuggestion? onShareSuggestion;
final OnGetUserById onGetUserById;

const SuggestionPage({
required this.suggestion,
required this.onGetUserById,
this.onUploadMultiplePhotos,
this.onSaveToGallery,
this.onShareSuggestion,
super.key,
});

Expand Down Expand Up @@ -98,6 +100,8 @@ class _SuggestionPageState extends State<SuggestionPage> {
body: _MainContent(
onSaveToGallery: widget.onSaveToGallery,
onCommentTap: stateManager.openDeletingCommentConfirmation,
onShareSuggestion: widget.onShareSuggestion,
suggestionId: widget.suggestion.id,
),
),
SafeArea(
Expand Down Expand Up @@ -173,10 +177,14 @@ class _SuggestionPageState extends State<SuggestionPage> {
class _MainContent extends StatelessWidget {
final ValueChanged<String> onCommentTap;
final OnSaveToGalleryCallback? onSaveToGallery;
final OnShareSuggestion? onShareSuggestion;
final String suggestionId;

const _MainContent({
required this.onCommentTap,
required this.suggestionId,
this.onSaveToGallery,
this.onShareSuggestion,
});

@override
Expand All @@ -194,6 +202,8 @@ class _MainContent extends StatelessWidget {
_UserInfo(
author: state.author,
isAnonymous: state.suggestion.isAnonymous,
suggestionId: suggestionId,
onShareSuggestion: onShareSuggestion,
),
_SuggestionInfo(
suggestion: state.suggestion,
Expand Down Expand Up @@ -232,10 +242,14 @@ class _MainContent extends StatelessWidget {
class _UserInfo extends StatelessWidget {
final SuggestionAuthor author;
final bool isAnonymous;
final String suggestionId;
final OnShareSuggestion? onShareSuggestion;

const _UserInfo({
required this.author,
required this.isAnonymous,
required this.suggestionId,
this.onShareSuggestion,
});

@override
Expand All @@ -258,6 +272,13 @@ class _UserInfo extends StatelessWidget {
style: context.theme.textTheme.bodyMedium,
),
),
if (onShareSuggestion != null)
IconButton(
onPressed: () {
onShareSuggestion!(suggestionId);
},
icon: const Icon(Icons.share),
),
],
),
);
Expand Down
134 changes: 77 additions & 57 deletions lib/src/presentation/pages/suggestions/suggestions_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:suggest_a_feature/src/presentation/pages/theme/theme_extension.d
import 'package:suggest_a_feature/src/presentation/pages/widgets/appbar_widget.dart';
import 'package:suggest_a_feature/src/presentation/pages/widgets/bottom_sheets/sorting_bottom_sheet.dart';
import 'package:suggest_a_feature/src/presentation/pages/widgets/fab.dart';
import 'package:suggest_a_feature/src/presentation/pages/widgets/state_listener.dart';
import 'package:suggest_a_feature/src/presentation/utils/assets_strings.dart';
import 'package:suggest_a_feature/src/presentation/utils/dimensions.dart';
import 'package:suggest_a_feature/src/presentation/utils/platform_check.dart';
Expand Down Expand Up @@ -40,6 +39,9 @@ class SuggestionsPage extends StatefulWidget {
/// Callback returning the current user (SuggestionAuthor).
final OnGetUserById onGetUserById;

/// Callback processing event sharing (void).
final OnShareSuggestion? onShareSuggestion;

/// AppBar title that will be displayed on the [SuggestionsPage].
final String? appBarTitle;

Expand All @@ -59,6 +61,9 @@ class SuggestionsPage extends StatefulWidget {
/// [navigatorKey] of your Router
final GlobalKey<NavigatorState>? navigatorKey;

/// Navigates to [SuggestionPage] if not `null`
final String? suggestionId;

const SuggestionsPage({
required this.userId,
required this.suggestionsDataSource,
Expand All @@ -69,10 +74,12 @@ class SuggestionsPage extends StatefulWidget {
this.isAdmin = false,
this.onSaveToGallery,
this.onUploadMultiplePhotos,
this.onShareSuggestion,
this.appBarTitle,
this.imageHeaders,
this.locale,
this.sortType = SortType.upvotes,
this.suggestionId,
super.key,
}) : assert(
(isAdmin && adminSettings != null) || !isAdmin,
Expand Down Expand Up @@ -103,68 +110,71 @@ class _SuggestionsPageState extends State<SuggestionsPage> {
Widget build(BuildContext context) {
return SuggestionsManager(
sortType: widget.sortType,
initialSuggestionId: widget.suggestionId,
child: Builder(
builder: (context) {
final stateManager = SuggestionsManager.of(context);
final state = stateManager.state;

return StateListener(
state: state,
listenWhen: (previous, current) =>
previous.type != current.type ||
previous.activeTab != current.activeTab ||
previous.sortType != current.sortType ||
previous.loading != current.loading,
child: Stack(
children: [
Scaffold(
appBar: SuggestionsAppBar(
onBackClick: () =>
(i.navigatorKey?.currentState ?? Navigator.of(context))
.pop(),
screenTitle:
widget.appBarTitle ?? localization.suggestAFeature,
),
backgroundColor: theme.backgroundColor ??
context.theme.scaffoldBackgroundColor,
body: state.loading
? const Center(child: CircularProgressIndicator())
: Stack(
children: [
_MainContent(
userId: widget.userId,
onTabChanged: (index) {
stateManager.changeActiveTab(
SuggestionStatus.values[index],
);
},
activeTab: state.activeTab,
onGetUserById: widget.onGetUserById,
onSaveToGallery: widget.onSaveToGallery,
onUploadMultiplePhotos:
widget.onUploadMultiplePhotos,
),
_BottomFab(
openCreateBottomSheet:
stateManager.openCreateBottomSheet,
),
],
),
if (state is SuggestionsRedirectState) {
return SuggestionPage(
suggestion: state.suggestion,
onUploadMultiplePhotos: widget.onUploadMultiplePhotos,
onSaveToGallery: widget.onSaveToGallery,
onGetUserById: widget.onGetUserById,
onShareSuggestion: widget.onShareSuggestion,
);
}
return Stack(
children: [
Scaffold(
appBar: SuggestionsAppBar(
onBackClick: () =>
(i.navigatorKey?.currentState ?? Navigator.of(context))
.pop(),
screenTitle:
widget.appBarTitle ?? localization.suggestAFeature,
),
backgroundColor: theme.backgroundColor ??
context.theme.scaffoldBackgroundColor,
body: state.loading
? const Center(child: CircularProgressIndicator())
: Stack(
children: [
_MainContent(
userId: widget.userId,
onTabChanged: (index) {
stateManager.changeActiveTab(
SuggestionStatus.values[index],
);
},
activeTab: state.activeTab,
onGetUserById: widget.onGetUserById,
onSaveToGallery: widget.onSaveToGallery,
onUploadMultiplePhotos:
widget.onUploadMultiplePhotos,
onShareSuggestion: widget.onShareSuggestion,
),
_BottomFab(
openCreateBottomSheet:
stateManager.openCreateBottomSheet,
),
],
),
),
if (state is CreateState)
_BottomSheet(
onSaveToGallery: widget.onSaveToGallery,
onUploadMultiplePhotos: widget.onUploadMultiplePhotos,
onCloseBottomSheet: stateManager.closeBottomSheet,
),
if (state is SortingState)
SortingBottomSheet(
closeBottomSheet: stateManager.closeBottomSheet,
value: state.sortType,
onChanged: stateManager.onSortTypeChanged,
),
if (state is CreateState)
_BottomSheet(
onSaveToGallery: widget.onSaveToGallery,
onUploadMultiplePhotos: widget.onUploadMultiplePhotos,
onCloseBottomSheet: stateManager.closeBottomSheet,
),
if (state is SortingState)
SortingBottomSheet(
closeBottomSheet: stateManager.closeBottomSheet,
value: state.sortType,
onChanged: stateManager.onSortTypeChanged,
),
],
),
],
);
},
),
Expand All @@ -179,6 +189,7 @@ class _MainContent extends StatefulWidget {
final OnGetUserById onGetUserById;
final OnSaveToGalleryCallback? onSaveToGallery;
final OnUploadMultiplePhotosCallback? onUploadMultiplePhotos;
final OnShareSuggestion? onShareSuggestion;

const _MainContent({
required this.userId,
Expand All @@ -187,6 +198,7 @@ class _MainContent extends StatefulWidget {
required this.onGetUserById,
required this.onSaveToGallery,
required this.onUploadMultiplePhotos,
required this.onShareSuggestion,
});

@override
Expand Down Expand Up @@ -227,6 +239,7 @@ class _MainContentState extends State<_MainContent>
onUploadMultiplePhotos: widget.onUploadMultiplePhotos,
onSaveToGallery: widget.onSaveToGallery,
onGetUserById: widget.onGetUserById,
onShareSuggestion: widget.onShareSuggestion,
userId: widget.userId,
onVote: stateManager.vote,
tabController: _tabController,
Expand Down Expand Up @@ -277,6 +290,7 @@ class _TabBarView extends StatelessWidget {
final OnGetUserById onGetUserById;
final OnSaveToGalleryCallback? onSaveToGallery;
final OnUploadMultiplePhotosCallback? onUploadMultiplePhotos;
final OnShareSuggestion? onShareSuggestion;
final void Function(SuggestionStatus status, int i) onVote;
final String userId;
final VoidCallback openSortingBottomSheet;
Expand All @@ -289,6 +303,7 @@ class _TabBarView extends StatelessWidget {
required this.openSortingBottomSheet,
this.onSaveToGallery,
this.onUploadMultiplePhotos,
this.onShareSuggestion,
});

@override
Expand All @@ -305,6 +320,7 @@ class _TabBarView extends StatelessWidget {
onGetUserById: onGetUserById,
onSaveToGallery: onSaveToGallery,
onUploadMultiplePhotos: onUploadMultiplePhotos,
onShareSuggestion: onShareSuggestion,
userId: userId,
vote: (i) => onVote(SuggestionStatus.requests, i),
openSortingBottomSheet: openSortingBottomSheet,
Expand All @@ -316,6 +332,7 @@ class _TabBarView extends StatelessWidget {
onGetUserById: onGetUserById,
onSaveToGallery: onSaveToGallery,
onUploadMultiplePhotos: onUploadMultiplePhotos,
onShareSuggestion: onShareSuggestion,
userId: userId,
vote: (i) => onVote(SuggestionStatus.inProgress, i),
openSortingBottomSheet: openSortingBottomSheet,
Expand All @@ -327,6 +344,7 @@ class _TabBarView extends StatelessWidget {
onGetUserById: onGetUserById,
onSaveToGallery: onSaveToGallery,
onUploadMultiplePhotos: onUploadMultiplePhotos,
onShareSuggestion: onShareSuggestion,
userId: userId,
vote: (i) => onVote(SuggestionStatus.completed, i),
openSortingBottomSheet: openSortingBottomSheet,
Expand All @@ -338,6 +356,7 @@ class _TabBarView extends StatelessWidget {
onGetUserById: onGetUserById,
onSaveToGallery: onSaveToGallery,
onUploadMultiplePhotos: onUploadMultiplePhotos,
onShareSuggestion: onShareSuggestion,
userId: userId,
vote: (i) => onVote(SuggestionStatus.declined, i),
openSortingBottomSheet: openSortingBottomSheet,
Expand All @@ -349,6 +368,7 @@ class _TabBarView extends StatelessWidget {
onGetUserById: onGetUserById,
onSaveToGallery: onSaveToGallery,
onUploadMultiplePhotos: onUploadMultiplePhotos,
onShareSuggestion: onShareSuggestion,
userId: userId,
vote: (i) => onVote(SuggestionStatus.duplicated, i),
openSortingBottomSheet: openSortingBottomSheet,
Expand Down
41 changes: 41 additions & 0 deletions lib/src/presentation/pages/suggestions/suggestions_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,47 @@ class CreateState extends SuggestionsState {
}
}

class SuggestionsRedirectState extends SuggestionsState {
final Suggestion suggestion;

const SuggestionsRedirectState({
required super.requests,
required super.inProgress,
required super.completed,
required super.declined,
required super.duplicated,
required super.sortType,
required super.loading,
required this.suggestion,
super.activeTab,
});

@override
SuggestionsRedirectState newState({
List<Suggestion>? requests,
List<Suggestion>? inProgress,
List<Suggestion>? completed,
List<Suggestion>? declined,
List<Suggestion>? duplicated,
SuggestionStatus? activeTab,
SortType? sortType,
bool? loading,
Suggestion? suggestion,
}) {
return SuggestionsRedirectState(
requests: requests ?? this.requests,
inProgress: inProgress ?? this.inProgress,
completed: completed ?? this.completed,
declined: declined ?? this.declined,
duplicated: duplicated ?? this.duplicated,
activeTab: activeTab ?? this.activeTab,
sortType: sortType ?? this.sortType,
loading: loading ?? this.loading,
suggestion: suggestion ?? this.suggestion,
);
}
}

class SortingState extends SuggestionsState {
const SortingState({
required super.requests,
Expand Down
Loading

0 comments on commit a2d1d5d

Please sign in to comment.