拍照App在vivo Y71上如果运行一次,然后退出, 下次再进的时候,点击FloatButton会直接打开相机,而不是弹出底部弹窗
来源:6-16 拍照APP开发-图片获取与图片展示【实战尝鲜】
_呵呵哒_
2019-05-06
如题 , 拍照App在vivo Y71上如果运行一次,然后退出, 下次再进的时候,点击FloatButton会直接打开相机,而不是弹出底部弹窗 ,还有一个问题, 在Android手机上,选择完图片后有时候不会显示出来,可能是没获取到,那么想请教下老师,有没有那种兼容库 , 谢谢!!
2回答
-
_呵呵哒_
提问者
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 ListTile(
leading: Icon(isCamera ? Icons.photo_camera : Icons.photo_library),
title: Text(title),
onTap: () {
_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 -
CrazyCodeBoy
2019-05-06
这个应该不是兼容问题,将代码贴出来,我帮你看下呢
012019-05-07
相似问题