Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions fast_shopping_bloc/lib/src/bloc/selected_shopping_list_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:bloc/bloc.dart';
import 'package:clock/clock.dart';
import 'package:fast_shopping_bloc/fast_shopping_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:share_plus/share_plus.dart';
import 'package:uuid/uuid.dart';

part 'selected_shopping_list_cubit.freezed.dart';
Expand Down Expand Up @@ -172,6 +173,24 @@ class SelectedShoppingListCubit extends Cubit<SelectedShoppingListState> {
_listsCubit.update(_updateItem(list, itemId, itemUpdate));
}

void shareItems(){
final list = _selectedList;
final shareSubjectString = list.name != '' ? '${list.name}:\n\n' : 'Shopping list:\n\n';
final doneRune = String.fromCharCodes(Runes('\u22A0\t'));
final undoneRune = String.fromCharCodes(Runes('\u25A1\t'));

try {
final shareItemsString = [for (var item in list.availableItems) item.doneAt != null ? doneRune + item.title : undoneRune + item.title].join('\n');

Share.share(shareSubjectString + shareItemsString);
}
catch (e) {
throw Exception(
'You must add at least one item to perform this action.',
);
}
}

/// Returns a `list` with an item with id `itemId` updated with `itemUpdate`.
static ShoppingList _updateItem(
ShoppingList list,
Expand Down
125 changes: 123 additions & 2 deletions fast_shopping_bloc/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "8.0.6"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
charcode:
dependency: transitive
description:
Expand Down Expand Up @@ -190,6 +197,16 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
flutter:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
freezed:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -294,7 +311,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.7.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -344,6 +361,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.11.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
pool:
dependency: transitive
description:
Expand All @@ -365,6 +389,48 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
share_plus:
dependency: "direct main"
description:
name: share_plus
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.2"
share_plus_linux:
dependency: transitive
description:
name: share_plus_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.4"
share_plus_macos:
dependency: transitive
description:
name: share_plus_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
share_plus_platform_interface:
dependency: transitive
description:
name: share_plus_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
share_plus_web:
dependency: transitive
description:
name: share_plus_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.4"
share_plus_windows:
dependency: transitive
description:
name: share_plus_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
shelf:
dependency: transitive
description:
Expand Down Expand Up @@ -393,6 +459,11 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
source_gen:
dependency: transitive
description:
Expand Down Expand Up @@ -491,13 +562,62 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
url_launcher:
dependency: transitive
description:
name: url_launcher
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.12"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.4"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.4"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
uuid:
dependency: "direct main"
description:
name: uuid
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.4"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
vm_service:
dependency: transitive
description:
Expand Down Expand Up @@ -534,4 +654,5 @@ packages:
source: hosted
version: "3.1.0"
sdks:
dart: ">=2.12.0 <3.0.0"
dart: ">=2.14.0 <3.0.0"
flutter: ">=2.5.0"
1 change: 1 addition & 0 deletions fast_shopping_bloc/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies:
collection: ^1.15.0
freezed_annotation: ^0.14.1
json_annotation: ^4.0.1
share_plus: ^3.0.2
uuid: ^3.0.4

dev_dependencies:
Expand Down
4 changes: 4 additions & 0 deletions lib/features/items/items_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ class ItemsScreen extends StatelessWidget {
resizeToAvoidBottomInset: false,
appBar: ItemsAppBar(
shoppingListsMode: shoppingListsMode,
onShareItems: listSelected
? (context) =>
context.read<SelectedShoppingListCubit>().shareItems()
: null,
onArchiveList: listSelected
? (context) => _onArchiveTap(context, selectedShoppingList!)
: null,
Expand Down
15 changes: 14 additions & 1 deletion lib/features/items/widgets/app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,30 @@ import 'app_logo.dart';

typedef _ContextCallback = void Function(BuildContext);

enum _MenuItem { archiveList, undoneAll, removeAllDone, settings }
enum _MenuItem { shareItems, archiveList, undoneAll, removeAllDone, settings }

class ItemsAppBar extends StatelessWidget implements PreferredSizeWidget {

const ItemsAppBar({
Key? key,
required this.shoppingListsMode,
this.onShareItems,
this.onArchiveList,
this.onUndoneAll,
this.onRemoveAllDone,
}) : super(key: key);

final ShoppingListsMode shoppingListsMode;
final _ContextCallback? onShareItems;
final _ContextCallback? onArchiveList;
final _ContextCallback? onUndoneAll;
final _ContextCallback? onRemoveAllDone;

void _onMenuItemSelected(BuildContext context, _MenuItem item) {
switch (item) {
case _MenuItem.shareItems:
onShareItems?.call(context);
break;
case _MenuItem.archiveList:
onArchiveList?.call(context);
break;
Expand Down Expand Up @@ -53,6 +59,13 @@ class ItemsAppBar extends StatelessWidget implements PreferredSizeWidget {
key: const ValueKey('menu'),
onSelected: (item) => _onMenuItemSelected(context, item),
itemBuilder: (context) => [
_PopupMenuItem(
value: _MenuItem.shareItems,
enabled: onArchiveList != null,
icon: const Icon(Icons.share),
label: Text(S.of(context)!.menu_share_list),
),
const PopupMenuDivider(),
if (shoppingListsMode == ShoppingListsMode.multiple)
_PopupMenuItem(
value: _MenuItem.archiveList,
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@
"@menu_settings": {
"description": "Opens the _Settings_ screen."
},
"menu_share_list": "Teile die Liste",
"@menu_share_list": {
"description": "Share list via 3rd party apps."
},
"remove_all_done_dialog_title": "Entferne alle erledigte",
"@remove_all_done_dialog_title": {},
"remove_all_done_dialog_body": "{count, plural, =1 {Bist du sicher, dass du 1 Element entfernen möchtest? Dieser Vorgang kann nicht rückgängig gemacht werden.} other {Bist du sicher, dass du alle {count} Elemente entfernen möchtest? Dieser Vorgang kann nicht rückgängig gemacht werden.}}",
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@
"@menu_settings": {
"description": "Opens the _Settings_ screen."
},
"menu_share_list": "Share list",
"@menu_share_list": {
"description": "Share list via 3rd party apps."
},
"remove_all_done_dialog_title": "Removing all done",
"@remove_all_done_dialog_title": {},
"remove_all_done_dialog_body": "{count, plural, =1 {Are you sure you want to remove 1 item? This operation cannot be undone.} other {Are you sure you want to remove all {count} items? This operation cannot be undone.}}",
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@
"@menu_settings": {
"description": "Opens the _Settings_ screen."
},
"menu_share_list": "Comparte la lista",
"@menu_share_list": {
"description": "Share list via 3rd party apps."
},
"remove_all_done_dialog_title": "Eliminando artículos marcados",
"@remove_all_done_dialog_title": {},
"remove_all_done_dialog_body": "{count, plural, =1 {¿Estás seguro que deseas eliminar 1 artículo? Esta operación no se puede deshacer.} other {¿Estás seguro que deseas eliminar todos {count} los artículos? Esta operación no se puede deshacer.}}",
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@
"@menu_settings": {
"description": "Opens the _Settings_ screen."
},
"menu_share_list": "Partager la liste",
"@menu_share_list": {
"description": "Share list via 3rd party apps."
},
"remove_all_done_dialog_title": "Suppression de tous les articles validés",
"@remove_all_done_dialog_title": {},
"remove_all_done_dialog_body": "{count, plural, =1 {Êtes-vous sûr de vouloir supprimer 1 article ? Cette opération ne peut pas être annulée.} other {Êtes-vous sûr de vouloir supprimer ces {count} articles ? Cette opération ne peut pas être annulée.}}",
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_it.arb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@
"@menu_settings": {
"description": "Opens the _Settings_ screen."
},
"menu_share_list": "Condivi la lista",
"@menu_share_list": {
"description": "Share list via 3rd party apps."
},
"remove_all_done_dialog_title": "Rimozione di tutti i contrassegnati",
"@remove_all_done_dialog_title": {},
"remove_all_done_dialog_body": "{count, plural, =1 {Sei sicuro di voler rimuovere 1 oggetto? Questa operazione non può essere annullata.} other {Sei sicuro di voler rimuovere tutti i {count} elementi? Questa operazione non può essere annullata.}}",
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_mk.arb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@
"@menu_settings": {
"description": "Opens the _Settings_ screen."
},
"menu_share_list": "споделете листа",
"@menu_share_list": {
"description": "Share list via 3rd party apps."
},
"remove_all_done_dialog_title": "Ги отстранувам сите готови",
"@remove_all_done_dialog_title": {},
"remove_all_done_dialog_body": "{count, plural, =1 {Дали сте сигурни дека сакате да отстраните 1 предмет? Оваа операција е трајна.} other {Дали сте сигурни дека сакате да ги избришете сите {count} предмета? Оваа операција е трајна.}}",
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_nl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@
"@menu_settings": {
"description": "Opens the _Settings_ screen."
},
"menu_share_list": "Deel de lijst",
"@menu_share_list": {
"description": "Share list via 3rd party apps."
},
"remove_all_done_dialog_title": "Verwijder alle voltooide artikelen",
"@remove_all_done_dialog_title": {},
"remove_all_done_dialog_body": "{count, plural, =1 {Weet u zeker dat u 1 artikel wilt verwijderen? Dit kan niet ongedaan gemaakt worden.} other {Weet u zeker dat u {count} artikelen wilt verwijderen? Dit kan niet ongedaan gemaakt worden.}}",
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@
"@menu_settings": {
"description": "Opens the _Settings_ screen."
},
"menu_share_list": "Udostępnij listę",
"@menu_share_list": {
"description": "Share list via 3rd party apps."
},
"remove_all_done_dialog_title": "Usuwanie wszystkich oznaczonych",
"@remove_all_done_dialog_title": {},
"remove_all_done_dialog_body": "{count, plural, =1 {Czy na pewno chcesz usunąć 1 element? Tej operacji nie można cofnąć.} few {Czy na pewno chcesz usunąć wszystkie {count} elementy? Tej operacji nie można cofnąć.} many {Czy na pewno chcesz usunąć wszystkie {count} elementów? Tej operacji nie można cofnąć.} other {Czy na pewno chcesz usunąć wszystkie {count} elementu? Tej operacji nie można cofnąć.}}",
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_ru.arb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@
"@menu_settings": {
"description": "Opens the _Settings_ screen."
},
"menu_share_list": "Поделитесь списком",
"@menu_share_list": {
"description": "Share list via 3rd party apps."
},
"remove_all_done_dialog_title": "Удалить все выполненные",
"@remove_all_done_dialog_title": {},
"remove_all_done_dialog_body": "{count, plural, =1 {Вы уверены, что хотите удалить 1 элемент? Эту операцию нельзя отменить.} few {Вы уверены, что хотите удалить все {count} элемента? Эту операцию нельзя отменить.} many {Вы уверены, что хотите удалить все {count} элементов? Эту операцию нельзя отменить.} other {Вы уверены, что хотите удалить все {count} элементов? Эту операцию нельзя отменить.}}",
Expand Down
Loading