在Colum控件下放入 ListTile控件 , 为什么ListTile控件的onTap会自动执行呢?手势控件包裹后就不会了
来源:6-16 拍照APP开发-图片获取与图片展示【实战尝鲜】
_呵呵哒_
2019-05-06
在Colum控件下放入 ListTile控件 , 为什么ListTile控件的onTap会自动执行呢?手势控件包裹后就不会自动执行了 ?很是疑惑 ? 望老师解惑,谢谢!
2回答
-
看情况是个bug啊,你的代码是怎么实现的呢,发出来我帮你检查下
022019-05-16 -
_呵呵哒_
提问者
2019-05-07
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'Camera.dart';
main() => runApp(MyApp());
String _title = '拍照App';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
theme: ThemeData(primaryColor: Colors.blue),
home: _PicturePage());
}
}
class _PicturePage extends StatefulWidget {
@override
_PictureState createState() => _PictureState();
}
class _PictureState extends State<_PicturePage> {
//保存获取的图片
List<File> _images = [];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(_title),
leading: GestureDetector(
onTap: () {
// Navigator.pop(context);
},
child: Icon(Icons.arrow_back),
),
),
body: Center(
child: _images == null || _images.length == 0
? Text('No Selector Image')
: Wrap(
spacing: 8.0,
runSpacing: 8.0,
children: _images.map((file) {
return _backWidget(file);
}).toList(),
),
),
floatingActionButton: FloatingActionButton(
onPressed: _showBottomSheet,
child: Icon(Icons.add_a_photo),
),
);
}
/*显示一个底部弹框*/
void _showBottomSheet() {
showModalBottomSheet(
context: context,
builder: (context) => Container(
height: 140.0,
child: Column(
children: <Widget>[
_item('拍照', true),
Divider(),
_item('从相册选择', false),
],
),
));
}
/*获取选择的图片*/
Future _getImages(bool isCamera) async {
Navigator.pop(context);
var image = await ImagePicker.pickImage(
source: isCamera ? ImageSource.camera : ImageSource.gallery);
assert(image != null);
setState(() {
if (image != null) _images.add(image);
print(_images);
});
}
/*BottomSheet列表项*/
/*Widget _item(String title, bool isCamera) {
return GestureDetector(
child: ListTile(
leading: Icon(isCamera ? Icons.photo_camera : Icons.photo_library),
title: Text(title),
onTap: () {
_getImages(isCamera);
},
),
);
}*/
Widget _item(String title, bool isCamera) {
return ListTile(
leading: Icon(isCamera ? Icons.photo_camera : Icons.photo_library),
title: Text(title),
onTap: () {
print(isCamera);
_getImages(isCamera);
},
);
}
/*显示的控件*/
Widget _backWidget(File file) {
return ClipRRect(
borderRadius: BorderRadius.circular(4.0),
child: Stack(
children: <Widget>[
Image.file(
file,
width: 80,
height: 80,
fit: BoxFit.fill,
),
Positioned(top: 2.0, right: 2.0, child: _closeBtn(file))
],
),
);
}
/*显示控件右上角的关闭按钮*/
Widget _closeBtn(File file) {
return GestureDetector(
onTap: () {
setState(() {
_images.remove(file);
});
},
child: ClipOval(
child: Container(
color: Colors.black45,
padding: EdgeInsets.all(4.0),
child: Icon(
Icons.close,
color: Colors.white,
size: 12.0,
),
),
),
);
}
}00
相似问题