DRY up some search and places code
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:drift/drift.dart' hide Column;
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
@ -181,9 +182,27 @@ class _SessionEditorState extends State<SessionEditor> {
|
||||
});
|
||||
}),
|
||||
FormSearchInput(
|
||||
title: 'Location (optional)',
|
||||
sessionController: sessionCreateController['address']!,
|
||||
service: GooglePlacesService(),
|
||||
optionalPayload: sessionPayload),
|
||||
callback: (content, service) async {
|
||||
if (content.imageReferences != null) {
|
||||
// get a random photo item from the returned result
|
||||
Map<String, dynamic> photo = content.imageReferences![
|
||||
Random().nextInt(content.imageReferences!.length)];
|
||||
|
||||
await service
|
||||
.fetchPhoto(photo['name'])
|
||||
.then((photoMap) {
|
||||
sessionPayload.photoUri = photoMap['photoUri'];
|
||||
});
|
||||
}
|
||||
|
||||
sessionPayload.address = content.address;
|
||||
sessionCreateController['address']!.text =
|
||||
content.description;
|
||||
service.finish();
|
||||
}),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 10, bottom: 10),
|
||||
child: TextFormField(
|
||||
@ -248,11 +267,15 @@ class _SessionEditorState extends State<SessionEditor> {
|
||||
i++) {
|
||||
PlatformFile file =
|
||||
sessionPayload.files![i];
|
||||
String? type = lookupMimeType(file.path!)!.split('/').first;
|
||||
String? type =
|
||||
lookupMimeType(file.path!)!
|
||||
.split('/')
|
||||
.first;
|
||||
Uint8List fileBytes =
|
||||
await file.xFile.readAsBytes();
|
||||
|
||||
MediaType mediaType = MediaType.localImage;
|
||||
MediaType mediaType =
|
||||
MediaType.localImage;
|
||||
if (type == "video") {
|
||||
mediaType = MediaType.localVideo;
|
||||
}
|
||||
@ -282,8 +305,7 @@ class _SessionEditorState extends State<SessionEditor> {
|
||||
_formKey.currentContext!, 'Submit');
|
||||
|
||||
if (widget.callback != null) {
|
||||
await widget
|
||||
.callback!();
|
||||
await widget.callback!();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user