|
|
|
@@ -1,6 +1,9 @@ |
|
|
|
import 'dart:io'; |
|
|
|
import 'dart:async'; |
|
|
|
|
|
|
|
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/widget_item_media.dart'; |
|
|
|
import 'package:farm_tpf/utils/const_color.dart'; |
|
|
|
import 'package:farm_tpf/utils/const_string.dart'; |
|
|
|
import 'package:flutter/cupertino.dart'; |
|
|
|
@@ -22,44 +25,71 @@ class _WidgetMediaHelperState extends State<WidgetMediaHelper> { |
|
|
|
String _retrieveDataError; |
|
|
|
|
|
|
|
final ImagePicker _picker = ImagePicker(); |
|
|
|
List<ItemMediaVM> items = [ |
|
|
|
ItemMediaVM('http://lorempixel.com/640/480', true), |
|
|
|
ItemMediaVM( |
|
|
|
'https://s3.amazonaws.com/uifaces/faces/twitter/rickdt/128.jpg', true), |
|
|
|
ItemMediaVM('http://lorempixel.com/640/480/food', true), |
|
|
|
ItemMediaVM('http://lorempixel.com/640/480/animals', true), |
|
|
|
ItemMediaVM('http://lorempixel.com/640/480/fashion', true), |
|
|
|
]; |
|
|
|
|
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
return Container( |
|
|
|
padding: EdgeInsets.all(8), |
|
|
|
child: Column( |
|
|
|
children: <Widget>[ |
|
|
|
_actionButton(), |
|
|
|
1 == 1 |
|
|
|
? 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, |
|
|
|
); |
|
|
|
children: <Widget>[ |
|
|
|
_actionButton(), |
|
|
|
SizedBox( |
|
|
|
height: 4.0, |
|
|
|
), |
|
|
|
_buildListPoster(), |
|
|
|
1 == 1 |
|
|
|
? 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()), |
|
|
|
], |
|
|
|
)); |
|
|
|
}, |
|
|
|
) |
|
|
|
: (isVideo ? _previewVideo() : _previewImage()), |
|
|
|
], |
|
|
|
)); |
|
|
|
} |
|
|
|
|
|
|
|
_buildListPoster() { |
|
|
|
return WrapContentHozListView( |
|
|
|
itemBuilder: (context, index) { |
|
|
|
var item = items[index]; |
|
|
|
return _WidgetItemMedia(item); |
|
|
|
}, |
|
|
|
separatorBuilder: (context, index) { |
|
|
|
return SizedBox(width: 14); |
|
|
|
}, |
|
|
|
list: items, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
Widget viewResult() { |
|
|
|
@@ -138,32 +168,37 @@ class _WidgetMediaHelperState extends State<WidgetMediaHelper> { |
|
|
|
Widget _actionButton() { |
|
|
|
return SizedBox( |
|
|
|
width: double.infinity, |
|
|
|
height: 55, |
|
|
|
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: Row( |
|
|
|
children: <Widget>[ |
|
|
|
Icon(Icons.image), |
|
|
|
Text( |
|
|
|
button_add_media, |
|
|
|
style: TextStyle( |
|
|
|
fontWeight: FontWeight.bold, color: COLOR_CONST.WHITE), |
|
|
|
) |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
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), |
|
|
|
) |
|
|
|
], |
|
|
|
), |
|
|
|
)), |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -358,3 +393,55 @@ class AspectRatioVideoState extends State<AspectRatioVideo> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
class _WidgetItemMedia extends StatelessWidget { |
|
|
|
final ItemMediaVM item; |
|
|
|
|
|
|
|
_WidgetItemMedia(this.item); |
|
|
|
|
|
|
|
BuildContext _context; |
|
|
|
|
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
_context = context; |
|
|
|
return GestureDetector( |
|
|
|
onTap: () { |
|
|
|
print("Show preview image or video"); |
|
|
|
}, |
|
|
|
child: Stack( |
|
|
|
alignment: Alignment.bottomCenter, |
|
|
|
overflow: Overflow.visible, |
|
|
|
children: <Widget>[ |
|
|
|
Positioned( |
|
|
|
child: ClipRRect( |
|
|
|
borderRadius: BorderRadius.circular(8), |
|
|
|
child: ShimmerImage( |
|
|
|
item.photo, |
|
|
|
width: 93, |
|
|
|
height: 124, |
|
|
|
fit: BoxFit.cover, |
|
|
|
), |
|
|
|
)), |
|
|
|
Positioned( |
|
|
|
top: -5, |
|
|
|
right: -5, |
|
|
|
child: IconButton( |
|
|
|
icon: Icon( |
|
|
|
Icons.cancel, |
|
|
|
color: Colors.redAccent, |
|
|
|
), |
|
|
|
onPressed: () { |
|
|
|
print("On tap delete media"); |
|
|
|
}), |
|
|
|
) |
|
|
|
], |
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
class ItemMediaVM { |
|
|
|
String photo; |
|
|
|
bool isVideo; |
|
|
|
|
|
|
|
ItemMediaVM(this.photo, this.isVideo); |
|
|
|
} |