|
|
|
|
|
|
|
|
import 'dart:io'; |
|
|
import 'dart:io'; |
|
|
import 'dart:async'; |
|
|
import 'dart:async'; |
|
|
|
|
|
|
|
|
|
|
|
import 'package:farm_tpf/custom_model/Media.dart'; |
|
|
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/bloc/media_helper_bloc.dart'; |
|
|
import 'package:farm_tpf/presentation/custom_widgets/hoz_list_view.dart'; |
|
|
import 'package:farm_tpf/presentation/custom_widgets/hoz_list_view.dart'; |
|
|
import 'package:farm_tpf/presentation/custom_widgets/shimmer_image.dart'; |
|
|
import 'package:farm_tpf/presentation/custom_widgets/shimmer_image.dart'; |
|
|
import 'package:farm_tpf/utils/const_color.dart'; |
|
|
import 'package:farm_tpf/utils/const_color.dart'; |
|
|
|
|
|
|
|
|
import 'package:flutter/cupertino.dart'; |
|
|
import 'package:flutter/cupertino.dart'; |
|
|
import 'package:flutter/foundation.dart'; |
|
|
import 'package:flutter/foundation.dart'; |
|
|
import 'package:flutter/material.dart'; |
|
|
import 'package:flutter/material.dart'; |
|
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart'; |
|
|
|
|
|
import 'package:get/get.dart'; |
|
|
|
|
|
import 'package:get/state_manager.dart'; |
|
|
import 'package:image_picker/image_picker.dart'; |
|
|
import 'package:image_picker/image_picker.dart'; |
|
|
import 'package:video_player/video_player.dart'; |
|
|
import 'package:video_player/video_player.dart'; |
|
|
|
|
|
|
|
|
class WidgetMediaHelper extends StatefulWidget { |
|
|
class WidgetMediaHelper extends StatefulWidget { |
|
|
|
|
|
final Function(List<String> filePaths) onChangeFiles; |
|
|
|
|
|
WidgetMediaHelper({@required this.onChangeFiles}); |
|
|
@override |
|
|
@override |
|
|
_WidgetMediaHelperState createState() => _WidgetMediaHelperState(); |
|
|
_WidgetMediaHelperState createState() => _WidgetMediaHelperState(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
class _WidgetMediaHelperState extends State<WidgetMediaHelper> { |
|
|
class _WidgetMediaHelperState extends State<WidgetMediaHelper> { |
|
|
|
|
|
final globalScaffoldKey = GlobalKey<ScaffoldState>(); |
|
|
PickedFile _imageFile; |
|
|
PickedFile _imageFile; |
|
|
dynamic _pickImageError; |
|
|
dynamic _pickImageError; |
|
|
bool isVideo = false; |
|
|
bool isVideo = false; |
|
|
|
|
|
|
|
|
String _retrieveDataError; |
|
|
String _retrieveDataError; |
|
|
|
|
|
|
|
|
final ImagePicker _picker = ImagePicker(); |
|
|
final ImagePicker _picker = ImagePicker(); |
|
|
List<ItemMediaVM> items = []; |
|
|
|
|
|
|
|
|
List<Media> currentItems = []; |
|
|
|
|
|
List<String> files = new List<String>(); |
|
|
|
|
|
var changeImageController = Get.put(ChangeImageController()); |
|
|
|
|
|
double imageWidth = 90; |
|
|
|
|
|
double imageHeight = 90; |
|
|
|
|
|
|
|
|
@override |
|
|
@override |
|
|
Widget build(BuildContext context) { |
|
|
|
|
|
return Container( |
|
|
|
|
|
padding: EdgeInsets.all(8), |
|
|
|
|
|
child: Column( |
|
|
|
|
|
children: <Widget>[ |
|
|
|
|
|
_actionButton(), |
|
|
|
|
|
SizedBox( |
|
|
|
|
|
height: 4.0, |
|
|
|
|
|
), |
|
|
|
|
|
_buildListPoster(), |
|
|
|
|
|
defaultTargetPlatform == TargetPlatform.android |
|
|
|
|
|
? FutureBuilder<void>( |
|
|
|
|
|
future: retrieveLostData(), |
|
|
|
|
|
builder: |
|
|
|
|
|
(BuildContext context, AsyncSnapshot<void> snapshot) { |
|
|
|
|
|
switch (snapshot.connectionState) { |
|
|
|
|
|
case ConnectionState.none: |
|
|
|
|
|
case ConnectionState.waiting: |
|
|
|
|
|
return const Text( |
|
|
|
|
|
'You have not yet picked an image.', |
|
|
|
|
|
textAlign: TextAlign.center, |
|
|
|
|
|
); |
|
|
|
|
|
case ConnectionState.done: |
|
|
|
|
|
return isVideo ? _previewVideo() : _previewImage(); |
|
|
|
|
|
default: |
|
|
|
|
|
if (snapshot.hasError) { |
|
|
|
|
|
return Text( |
|
|
|
|
|
'Pick image/video error: ${snapshot.error}}', |
|
|
|
|
|
textAlign: TextAlign.center, |
|
|
|
|
|
); |
|
|
|
|
|
} else { |
|
|
|
|
|
return const Text( |
|
|
|
|
|
'You have not yet picked an image.', |
|
|
|
|
|
textAlign: TextAlign.center, |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
) |
|
|
|
|
|
: (isVideo ? _previewVideo() : _previewImage()), |
|
|
|
|
|
], |
|
|
|
|
|
)); |
|
|
|
|
|
|
|
|
void initState() { |
|
|
|
|
|
super.initState(); |
|
|
|
|
|
changeImageController.initValue(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
_buildListPoster() { |
|
|
|
|
|
return WrapContentHozListView( |
|
|
|
|
|
itemBuilder: (context, index) { |
|
|
|
|
|
var item = items[index]; |
|
|
|
|
|
return _WidgetItemMedia(item); |
|
|
|
|
|
}, |
|
|
|
|
|
separatorBuilder: (context, index) { |
|
|
|
|
|
return SizedBox(width: 14); |
|
|
|
|
|
}, |
|
|
|
|
|
list: items, |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
@override |
|
|
|
|
|
Widget build(BuildContext context) { |
|
|
|
|
|
return BlocProvider<MediaHelperBloc>( |
|
|
|
|
|
create: (BuildContext contextA) => |
|
|
|
|
|
MediaHelperBloc()..add(ChangeListMedia(items: currentItems)), |
|
|
|
|
|
child: BlocBuilder<MediaHelperBloc, MediaHelperState>( |
|
|
|
|
|
builder: (contextB, state) { |
|
|
|
|
|
if (state is MediaHelperFailure) { |
|
|
|
|
|
return Container(); |
|
|
|
|
|
} else if (state is MediaHelperSuccess) { |
|
|
|
|
|
return Container( |
|
|
|
|
|
padding: EdgeInsets.all(8), |
|
|
|
|
|
child: Column( |
|
|
|
|
|
children: <Widget>[ |
|
|
|
|
|
SizedBox( |
|
|
|
|
|
width: double.infinity, |
|
|
|
|
|
height: 44, |
|
|
|
|
|
child: FlatButton( |
|
|
|
|
|
onPressed: () { |
|
|
|
|
|
showDialog( |
|
|
|
|
|
context: context, |
|
|
|
|
|
barrierDismissible: true, |
|
|
|
|
|
builder: (context) => Opacity( |
|
|
|
|
|
child: multipleChoice(contextB), |
|
|
|
|
|
opacity: 1, |
|
|
|
|
|
)); |
|
|
|
|
|
}, |
|
|
|
|
|
color: COLOR_CONST.DEFAULT, |
|
|
|
|
|
shape: RoundedRectangleBorder( |
|
|
|
|
|
borderRadius: new BorderRadius.circular(7.0), |
|
|
|
|
|
), |
|
|
|
|
|
child: Center( |
|
|
|
|
|
child: Row( |
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
|
|
|
children: <Widget>[ |
|
|
|
|
|
Icon(Icons.image, color: Colors.white), |
|
|
|
|
|
SizedBox( |
|
|
|
|
|
width: 8.0, |
|
|
|
|
|
), |
|
|
|
|
|
Text( |
|
|
|
|
|
button_add_media, |
|
|
|
|
|
style: TextStyle( |
|
|
|
|
|
fontWeight: FontWeight.bold, |
|
|
|
|
|
color: COLOR_CONST.WHITE), |
|
|
|
|
|
) |
|
|
|
|
|
], |
|
|
|
|
|
), |
|
|
|
|
|
)), |
|
|
|
|
|
), |
|
|
|
|
|
SizedBox( |
|
|
|
|
|
height: 4.0, |
|
|
|
|
|
), |
|
|
|
|
|
Container( |
|
|
|
|
|
height: 150, |
|
|
|
|
|
child: _buildListPoster(), |
|
|
|
|
|
), |
|
|
|
|
|
defaultTargetPlatform == TargetPlatform.android |
|
|
|
|
|
? FutureBuilder<void>( |
|
|
|
|
|
future: retrieveLostData(), |
|
|
|
|
|
builder: (BuildContext context, |
|
|
|
|
|
AsyncSnapshot<void> snapshot) { |
|
|
|
|
|
switch (snapshot.connectionState) { |
|
|
|
|
|
case ConnectionState.none: |
|
|
|
|
|
case ConnectionState.waiting: |
|
|
|
|
|
return const Text( |
|
|
|
|
|
'You have not yet picked an image.', |
|
|
|
|
|
textAlign: TextAlign.center, |
|
|
|
|
|
); |
|
|
|
|
|
case ConnectionState.done: |
|
|
|
|
|
return isVideo |
|
|
|
|
|
? _previewVideo() |
|
|
|
|
|
: _previewImage(); |
|
|
|
|
|
default: |
|
|
|
|
|
if (snapshot.hasError) { |
|
|
|
|
|
return Text( |
|
|
|
|
|
'Pick image/video error: ${snapshot.error}}', |
|
|
|
|
|
textAlign: TextAlign.center, |
|
|
|
|
|
); |
|
|
|
|
|
} else { |
|
|
|
|
|
return const Text( |
|
|
|
|
|
'You have not yet picked an image.', |
|
|
|
|
|
textAlign: TextAlign.center, |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
) |
|
|
|
|
|
: (isVideo ? _previewVideo() : _previewImage()), |
|
|
|
|
|
], |
|
|
|
|
|
)); |
|
|
|
|
|
} |
|
|
|
|
|
return Container(); |
|
|
|
|
|
})); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Widget viewResult() { |
|
|
|
|
|
FutureBuilder<void>( |
|
|
|
|
|
future: retrieveLostData(), |
|
|
|
|
|
builder: (BuildContext context, AsyncSnapshot<void> snapshot) { |
|
|
|
|
|
switch (snapshot.connectionState) { |
|
|
|
|
|
case ConnectionState.none: |
|
|
|
|
|
case ConnectionState.waiting: |
|
|
|
|
|
return const Text( |
|
|
|
|
|
'You have not yet picked an image.', |
|
|
|
|
|
textAlign: TextAlign.center, |
|
|
|
|
|
); |
|
|
|
|
|
case ConnectionState.done: |
|
|
|
|
|
return isVideo ? _previewVideo() : _previewImage(); |
|
|
|
|
|
default: |
|
|
|
|
|
if (snapshot.hasError) { |
|
|
|
|
|
return Text( |
|
|
|
|
|
'Pick image/video error: ${snapshot.error}}', |
|
|
|
|
|
textAlign: TextAlign.center, |
|
|
|
|
|
); |
|
|
|
|
|
} else { |
|
|
|
|
|
return const Text( |
|
|
|
|
|
'You have not yet picked an image.', |
|
|
|
|
|
textAlign: TextAlign.center, |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
_buildListPoster() { |
|
|
|
|
|
return BlocBuilder<MediaHelperBloc, MediaHelperState>( |
|
|
|
|
|
builder: (context, state) { |
|
|
|
|
|
if (state is MediaHelperSuccess) { |
|
|
|
|
|
return WrapContentHozListView( |
|
|
|
|
|
itemBuilder: (context, index) { |
|
|
|
|
|
var item = state.items[index]; |
|
|
|
|
|
return _WidgetItemMedia( |
|
|
|
|
|
item: item, |
|
|
|
|
|
deleteImage: (item) { |
|
|
|
|
|
files.remove(item.pathFile); |
|
|
|
|
|
currentItems.remove(item); |
|
|
|
|
|
widget.onChangeFiles(files); |
|
|
|
|
|
BlocProvider.of<MediaHelperBloc>(context) |
|
|
|
|
|
.add(ChangeListMedia(items: currentItems)); |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
|
|
|
separatorBuilder: (context, index) { |
|
|
|
|
|
return SizedBox(width: 14); |
|
|
|
|
|
}, |
|
|
|
|
|
list: state.items, |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
return Container(); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Widget multipleChoice() { |
|
|
|
|
|
|
|
|
Widget multipleChoice(BuildContext context) { |
|
|
return CupertinoAlertDialog( |
|
|
return CupertinoAlertDialog( |
|
|
title: Text(label_title_select_media), |
|
|
title: Text(label_title_select_media), |
|
|
actions: <Widget>[ |
|
|
actions: <Widget>[ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Widget _actionButton() { |
|
|
Widget _actionButton() { |
|
|
return SizedBox( |
|
|
|
|
|
width: double.infinity, |
|
|
|
|
|
height: 44, |
|
|
|
|
|
child: FlatButton( |
|
|
|
|
|
onPressed: () { |
|
|
|
|
|
showDialog( |
|
|
|
|
|
context: context, |
|
|
|
|
|
barrierDismissible: true, |
|
|
|
|
|
builder: (context) => Opacity( |
|
|
|
|
|
child: multipleChoice(), |
|
|
|
|
|
opacity: 1, |
|
|
|
|
|
)); |
|
|
|
|
|
}, |
|
|
|
|
|
color: COLOR_CONST.DEFAULT, |
|
|
|
|
|
shape: RoundedRectangleBorder( |
|
|
|
|
|
borderRadius: new BorderRadius.circular(7.0), |
|
|
|
|
|
), |
|
|
|
|
|
child: Center( |
|
|
|
|
|
child: Row( |
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
|
|
|
children: <Widget>[ |
|
|
|
|
|
Icon(Icons.image, color: Colors.white), |
|
|
|
|
|
SizedBox( |
|
|
|
|
|
width: 8.0, |
|
|
|
|
|
), |
|
|
|
|
|
Text( |
|
|
|
|
|
button_add_media, |
|
|
|
|
|
style: TextStyle( |
|
|
|
|
|
fontWeight: FontWeight.bold, color: COLOR_CONST.WHITE), |
|
|
|
|
|
) |
|
|
|
|
|
], |
|
|
|
|
|
|
|
|
return BlocListener<MediaHelperBloc, MediaHelperState>( |
|
|
|
|
|
listener: (context, state) { |
|
|
|
|
|
SizedBox( |
|
|
|
|
|
width: double.infinity, |
|
|
|
|
|
height: 44, |
|
|
|
|
|
child: FlatButton( |
|
|
|
|
|
onPressed: () { |
|
|
|
|
|
showDialog( |
|
|
|
|
|
context: context, |
|
|
|
|
|
barrierDismissible: true, |
|
|
|
|
|
builder: (context) => Opacity( |
|
|
|
|
|
child: Text(""), |
|
|
|
|
|
opacity: 1, |
|
|
|
|
|
)); |
|
|
|
|
|
}, |
|
|
|
|
|
color: COLOR_CONST.DEFAULT, |
|
|
|
|
|
shape: RoundedRectangleBorder( |
|
|
|
|
|
borderRadius: new BorderRadius.circular(7.0), |
|
|
), |
|
|
), |
|
|
)), |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
child: Center( |
|
|
|
|
|
child: Row( |
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
|
|
|
children: <Widget>[ |
|
|
|
|
|
Icon(Icons.image, color: Colors.white), |
|
|
|
|
|
SizedBox( |
|
|
|
|
|
width: 8.0, |
|
|
|
|
|
), |
|
|
|
|
|
Text( |
|
|
|
|
|
button_add_media, |
|
|
|
|
|
style: TextStyle( |
|
|
|
|
|
fontWeight: FontWeight.bold, color: COLOR_CONST.WHITE), |
|
|
|
|
|
) |
|
|
|
|
|
], |
|
|
|
|
|
), |
|
|
|
|
|
)), |
|
|
|
|
|
); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Future<void> _playVideo(PickedFile file) async { |
|
|
Future<void> _playVideo(PickedFile file) async { |
|
|
|
|
|
|
|
|
await _controller.initialize(); |
|
|
await _controller.initialize(); |
|
|
await _controller.setLooping(true); |
|
|
await _controller.setLooping(true); |
|
|
await _controller.play(); |
|
|
await _controller.play(); |
|
|
setState(() {}); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void _onImageButtonPressed(ImageSource source, {BuildContext context}) async { |
|
|
|
|
|
|
|
|
_onImageButtonPressed(ImageSource source, {BuildContext context}) async { |
|
|
if (_controller != null) { |
|
|
if (_controller != null) { |
|
|
await _controller.setVolume(0.0); |
|
|
await _controller.setVolume(0.0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
final pickedFile = await _picker.getImage( |
|
|
final pickedFile = await _picker.getImage( |
|
|
source: source, |
|
|
source: source, |
|
|
maxWidth: maxWidth, |
|
|
|
|
|
maxHeight: maxHeight, |
|
|
|
|
|
|
|
|
maxWidth: imageWidth, |
|
|
|
|
|
maxHeight: imageHeight, |
|
|
imageQuality: quality, |
|
|
imageQuality: quality, |
|
|
); |
|
|
); |
|
|
setState(() { |
|
|
|
|
|
_imageFile = pickedFile; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Get.find<ChangeImageController>().updateFile(pickedFile); |
|
|
|
|
|
Media newMedia = Media() |
|
|
|
|
|
..isVideo = false |
|
|
|
|
|
..isServerFile = false |
|
|
|
|
|
..pathFile = pickedFile.path; |
|
|
|
|
|
currentItems.add(newMedia); |
|
|
|
|
|
files.add(pickedFile.path); |
|
|
|
|
|
BlocProvider.of<MediaHelperBloc>(context) |
|
|
|
|
|
..add(ChangeListMedia(items: currentItems)); |
|
|
|
|
|
widget.onChangeFiles(files); |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
setState(() { |
|
|
|
|
|
_pickImageError = e; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
Get.find<ChangeImageController>().updateFileError(e); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@override |
|
|
@override |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Widget _previewImage() { |
|
|
Widget _previewImage() { |
|
|
final Text retrieveError = _getRetrieveErrorWidget(); |
|
|
|
|
|
if (retrieveError != null) { |
|
|
|
|
|
return retrieveError; |
|
|
|
|
|
} |
|
|
|
|
|
if (_imageFile != null) { |
|
|
|
|
|
var imageResult = |
|
|
|
|
|
Image.file(File(_imageFile.path), width: 100, height: 100); |
|
|
|
|
|
setState(() { |
|
|
|
|
|
items.insert(0, ItemMediaVM(_imageFile.path, false, imageResult)); |
|
|
|
|
|
}); |
|
|
|
|
|
return Container( |
|
|
|
|
|
child: Text("ok"), |
|
|
|
|
|
); |
|
|
|
|
|
} else if (_pickImageError != null) { |
|
|
|
|
|
return Text( |
|
|
|
|
|
'Pick image error: $_pickImageError', |
|
|
|
|
|
textAlign: TextAlign.center, |
|
|
|
|
|
); |
|
|
|
|
|
} else { |
|
|
|
|
|
return const Text( |
|
|
|
|
|
'You have not yet picked an image.', |
|
|
|
|
|
textAlign: TextAlign.center, |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return Builder(builder: (context) { |
|
|
|
|
|
final Text retrieveError = _getRetrieveErrorWidget(); |
|
|
|
|
|
if (retrieveError != null) { |
|
|
|
|
|
return retrieveError; |
|
|
|
|
|
} |
|
|
|
|
|
if (_imageFile != null) { |
|
|
|
|
|
var imageResult = |
|
|
|
|
|
Image.file(File(_imageFile.path), width: imageWidth, height: 100); |
|
|
|
|
|
Media newMedia = Media() |
|
|
|
|
|
..isVideo = false |
|
|
|
|
|
..isServerFile = false |
|
|
|
|
|
..pathFile = _imageFile.path; |
|
|
|
|
|
currentItems.add(newMedia); |
|
|
|
|
|
BlocProvider.of<MediaHelperBloc>(context) |
|
|
|
|
|
.add(ChangeListMedia(items: currentItems)); |
|
|
|
|
|
//widget.onChangeFiles(files); |
|
|
|
|
|
return Container( |
|
|
|
|
|
child: Text("ok"), |
|
|
|
|
|
); |
|
|
|
|
|
} else if (_pickImageError != null) { |
|
|
|
|
|
return Text( |
|
|
|
|
|
'Pick image error: $_pickImageError', |
|
|
|
|
|
textAlign: TextAlign.center, |
|
|
|
|
|
); |
|
|
|
|
|
} else { |
|
|
|
|
|
return const Text( |
|
|
|
|
|
'You have not yet picked an image.', |
|
|
|
|
|
textAlign: TextAlign.center, |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Future<void> retrieveLostData() async { |
|
|
Future<void> retrieveLostData() async { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
class _WidgetItemMedia extends StatelessWidget { |
|
|
class _WidgetItemMedia extends StatelessWidget { |
|
|
final ItemMediaVM item; |
|
|
|
|
|
|
|
|
ItemMediaCallback deleteImage; |
|
|
|
|
|
final Media item; |
|
|
|
|
|
|
|
|
_WidgetItemMedia(this.item); |
|
|
|
|
|
|
|
|
_WidgetItemMedia({@required this.item, @required this.deleteImage}); |
|
|
|
|
|
|
|
|
BuildContext _context; |
|
|
BuildContext _context; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Positioned( |
|
|
Positioned( |
|
|
child: ClipRRect( |
|
|
child: ClipRRect( |
|
|
borderRadius: BorderRadius.circular(8), |
|
|
borderRadius: BorderRadius.circular(8), |
|
|
child: item.image == null |
|
|
|
|
|
|
|
|
child: item.isServerFile |
|
|
? ShimmerImage( |
|
|
? ShimmerImage( |
|
|
item.photo, |
|
|
|
|
|
|
|
|
item.pathFile, |
|
|
width: 93, |
|
|
width: 93, |
|
|
height: 124, |
|
|
height: 124, |
|
|
fit: BoxFit.cover, |
|
|
fit: BoxFit.cover, |
|
|
) |
|
|
) |
|
|
: Image.file(File(item.photo), width: 100, height: 100), |
|
|
|
|
|
|
|
|
: Image.file(File(item.pathFile), width: 100, height: 100), |
|
|
)), |
|
|
)), |
|
|
Positioned( |
|
|
Positioned( |
|
|
top: -5, |
|
|
top: -5, |
|
|
|
|
|
|
|
|
), |
|
|
), |
|
|
onPressed: () { |
|
|
onPressed: () { |
|
|
print("On tap delete media"); |
|
|
print("On tap delete media"); |
|
|
|
|
|
deleteImage(item); |
|
|
}), |
|
|
}), |
|
|
) |
|
|
) |
|
|
], |
|
|
], |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
typedef ItemMediaCallback = void Function(Media item); |
|
|
|
|
|
|
|
|
class ItemMediaVM { |
|
|
class ItemMediaVM { |
|
|
String photo; |
|
|
String photo; |
|
|
bool isVideo; |
|
|
bool isVideo; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ItemMediaVM(this.photo, this.isVideo, this.image); |
|
|
ItemMediaVM(this.photo, this.isVideo, this.image); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class ChangeImageController extends GetxController { |
|
|
|
|
|
PickedFile _imageFile; |
|
|
|
|
|
dynamic _pickImageError; |
|
|
|
|
|
void initValue() { |
|
|
|
|
|
update(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void updateFile(PickedFile imageFile) { |
|
|
|
|
|
_imageFile = imageFile; |
|
|
|
|
|
update(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void updateFileError(dynamic pickImageError) { |
|
|
|
|
|
_pickImageError = pickImageError; |
|
|
|
|
|
update(); |
|
|
|
|
|
} |
|
|
|
|
|
} |