Skip to content

Commit

Permalink
feat: add pickMultiImage #16
Browse files Browse the repository at this point in the history
  • Loading branch information
okodeee committed Dec 4, 2023
1 parent bdd5a85 commit 558f353
Showing 1 changed file with 51 additions and 38 deletions.
89 changes: 51 additions & 38 deletions lib/view/writing_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class WritingView extends StatefulWidget {
}

class _WritingViewState extends State<WritingView> {
String gpsApiKey = '';
String gpsApiKey = 'AIzaSyCduGt83ykiAOLOru3gKKMvEh4_9l6uT0A';

DateTime? selectedDate;
TextEditingController titleController = TextEditingController();
Expand All @@ -29,7 +29,7 @@ class _WritingViewState extends State<WritingView> {

final picker = ImagePicker();

XFile? pickedFile;
List<XFile?> _images = [];
Exif? exif;
Map<String, Object>? attributes;
DateTime? shootingDate;
Expand All @@ -41,7 +41,8 @@ class _WritingViewState extends State<WritingView> {
}

Future<void> showError(Object e) async {
debugPrintStack(label: e.toString(), stackTrace: e is Error ? e.stackTrace : null);
debugPrintStack(
label: e.toString(), stackTrace: e is Error ? e.stackTrace : null);

return showDialog<void>(
context: context,
Expand All @@ -68,13 +69,18 @@ class _WritingViewState extends State<WritingView> {
);
}

Future getImage() async {
pickedFile = await picker.pickImage(source: ImageSource.gallery);
if (pickedFile == null) {
Future getImages() async {
List<XFile>? pickedFiles = await picker.pickMultiImage();
if (pickedFiles == null) {
return;
}
setState(() {
_images.addAll(pickedFiles);
});
print(pickedFiles.length);

exif = await Exif.fromPath(pickedFile!.path);

exif = await Exif.fromPath(pickedFiles[0]!.path);
attributes = await exif!.getAttributes();
shootingDate = await exif!.getOriginalDate();
coordinates = await exif!.getLatLong();
Expand All @@ -84,10 +90,13 @@ class _WritingViewState extends State<WritingView> {
print(coordinates);

final gpsUrl =
'https://maps.googleapis.com/maps/api/geocode/json?latlng=${coordinates!.latitude},${coordinates!.longitude}&key=$gpsApiKey&language=ko';
'https://maps.googleapis.com/maps/api/geocode/json?latlng=${coordinates!
.latitude},${coordinates!.longitude}&key=$gpsApiKey&language=ko';
final responseGps = await http.get(Uri.parse(gpsUrl));
final formatted_address = jsonDecode(responseGps.body)['results'][0]['formatted_address'];
ETALocation = jsonDecode(responseGps.body)['results'][0]['address_components'][2]['long_name'];
final formatted_address = jsonDecode(
responseGps.body)['results'][0]['formatted_address'];
ETALocation = jsonDecode(
responseGps.body)['results'][0]['address_components'][3]['long_name'];
print(ETALocation);


Expand All @@ -97,16 +106,6 @@ class _WritingViewState extends State<WritingView> {
});
}

Future closeImage() async {
await exif?.close();
shootingDate = null;
attributes = {};
exif = null;
coordinates = null;

setState(() {});
}


String postCode = '';
String address = '';
Expand Down Expand Up @@ -143,7 +142,10 @@ class _WritingViewState extends State<WritingView> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildPhotoArea(),
SizedBox(
width: MediaQuery.of(context).size.width - 50,
child: _buildPhotoArea(),
),
Text(
'날짜',
style: TextStyle(fontSize: 17.0, fontWeight: FontWeight.w700),
Expand Down Expand Up @@ -271,24 +273,35 @@ class _WritingViewState extends State<WritingView> {


Widget _buildPhotoArea() {
return pickedFile == null
? Container(
width: 100,
return _images.isNotEmpty
? SizedBox(
height: 100,
child: IconButton(
onPressed: () {
getImage();
},
icon: Icon(Icons.camera_alt),
color: Color(0xFF8474F7),
// If atleast 1 images is selected
)
)
: Container(
width: 100,
height: 100,
child: Image.file(File(pickedFile!.path)),

child: ListView.builder(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemCount: _images.length,
itemBuilder: (context, index) {
return Container(
margin: EdgeInsets.only(right: 8.0),
width: 100,
height: 100,
child: Image.file(File(_images[index]!.path),
fit: BoxFit.cover,
),
);
}
),
)
: Container(
width: 100,
height: 100,
child: IconButton(
onPressed: () {
getImages();
},
icon: Icon(Icons.camera_alt),
color: Color(0xFF8474F7),
)
);
}
}

0 comments on commit 558f353

Please sign in to comment.