From a6346c34eda646194f654641b5d357a47f81af97 Mon Sep 17 00:00:00 2001 From: Lucas Delanier Date: Sun, 30 Jul 2023 20:01:02 +0200 Subject: [PATCH] choice between camera and gallery --- .../components/editable_post_component.dart | 46 +++++++++++++++++-- .../lib/screens/search_location_screen.dart | 4 +- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/Sources/justMUSIC/lib/components/editable_post_component.dart b/Sources/justMUSIC/lib/components/editable_post_component.dart index f66759f..960344e 100644 --- a/Sources/justMUSIC/lib/components/editable_post_component.dart +++ b/Sources/justMUSIC/lib/components/editable_post_component.dart @@ -4,6 +4,7 @@ import 'package:animated_appear/animated_appear.dart'; import 'package:auto_size_text/auto_size_text.dart'; import 'package:circular_reveal_animation/circular_reveal_animation.dart'; import 'package:flutter/Material.dart'; +import 'package:flutter/cupertino.dart'; import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -52,9 +53,9 @@ class _EditablePostComponentState extends State super.initState(); } - Future pickImage() async { + Future pickImage(ImageSource source) async { try { - final image = await ImagePicker().pickImage(source: ImageSource.gallery); + final image = await ImagePicker().pickImage(source: source); if (image == null) return; final imageTemp = File(image.path); setState(() { @@ -321,7 +322,7 @@ class _EditablePostComponentState extends State image = null; }); } else { - pickImage(); + _showActionSheet(context); } } @@ -334,4 +335,43 @@ class _EditablePostComponentState extends State searchLocation(); } } + + void _showActionSheet(BuildContext context) { + showCupertinoModalPopup( + context: context, + barrierColor: Colors.black.withOpacity(0.5), + builder: (BuildContext context) => Container( + color: Colors.black, + child: CupertinoActionSheet( + title: Text( + 'Ajouter une photo', + style: GoogleFonts.plusJakartaSans(fontWeight: FontWeight.bold), + ), + actions: [ + CupertinoActionSheetAction( + onPressed: () { + pickImage(ImageSource.gallery); + Navigator.pop(context); + }, + child: const Text('Gallerie'), + ), + CupertinoActionSheetAction( + onPressed: () { + pickImage(ImageSource.camera); + Navigator.pop(context); + }, + child: const Text('Prendre un selfie'), + ), + ], + cancelButton: CupertinoActionSheetAction( + isDestructiveAction: true, + onPressed: () { + Navigator.pop(context); + }, + child: const Text('Annuler'), + ), + ), + ), + ); + } } diff --git a/Sources/justMUSIC/lib/screens/search_location_screen.dart b/Sources/justMUSIC/lib/screens/search_location_screen.dart index 73f6d1a..82d8261 100644 --- a/Sources/justMUSIC/lib/screens/search_location_screen.dart +++ b/Sources/justMUSIC/lib/screens/search_location_screen.dart @@ -1,6 +1,7 @@ import 'dart:ui'; import 'package:flutter/Material.dart'; +import 'package:flutter/cupertino.dart'; import '../components/city_list_component.dart'; import '../services/GeoApi.dart'; @@ -71,7 +72,8 @@ class _SearchCityScreenState extends State { }); } else { return Center( - child: CircularProgressIndicator( + child: CupertinoActivityIndicator( + radius: 15, color: grayColor, ), );