如何在Flutter中仅访问前置摄像头

时间:2020-08-25 07:57:41

标签: android flutter dart

在Flutter中打开“相机视图”时,我想访问唯一的前置相机。

我的以下代码可以很好地打开,捕获图像,然后在我的图像中显示图像文件。 但是我想限制后置摄像头,只想访问前置摄像头。

import 'package:image_picker/image_picker.dart';
class SecondPage extends StatefulWidget {
  final value;


class SecondPageState extends State<SecondPage> {
File imagefile;
  openCamera(BuildContext context)async{
    var picture = await ImagePicker.pickImage(source: ImageSource.camera);
    setState(() {
      imagefile = picture;
    }
    );
  }


 showImage(){
  if(imagefile == null){
    return Text(" My image  here");
  
  }else {
    Image.file(imagefile,width:400,height:400);
  }
}
}

 body: 
        SafeArea(
                  child: Container(margin: EdgeInsets.only(top: 0,left: 00),
            child:

 Row( children: [ cameraButton(),],
    ),


Widget deviceButton() {
    return RaisedButton( 
      child: new Text('Camera button',)

onPressed: () {

         openCamera(context);
        var value = new MaterialPageRoute(
          builder: (BuildContext context) => new CameraAccess(value:imagefile ),
          );
          Navigator.of(context).push(value);
      }, 
    );

0 个答案:

没有答案