【发布时间】:2021-02-25 08:46:52
【问题描述】:
我最近开始编写有关 Flutter 和 dart 的代码,并且正在尝试学习它。在开发应用程序时,我试图将我的第一个屏幕上的一个按钮链接到另一个我启动相机以拍照的屏幕。
Future<void> main() async {
// Ensure that plugin services are initialized so that `availableCameras()`
// can be called before 'runApp()'
WidgetsFlutterBinding.ensureInitialized();
// Obtain a list of the available cameras on the device.
final cameras = await availableCameras();
// Get a specific camera from the list of available cameras.
final firstCamera = cameras.first;
runApp(
MaterialApp(
theme: ThemeData.dark(),
title: "Ipm-p2",
home: Scaffold(
appBar: AppBar(title: const Text("Ipm-p2")),
body: MyStatelessWidget(firstCamera),
),
/*TakePictureScreen(
// Pass the appropriate camera to the TakePictureScreen widget.
camera: firstCamera,
),*/
),
);
}
MyStatelessWidget 是我的第一个屏幕,其中有启动相机的按钮:
/// This is the stateless widget that the main application instantiates.
class MyStatelessWidget extends StatelessWidget {
MyStatelessWidget(CameraDescription firstCamera, {Key key, this.camera}) : super(key: key);
final CameraDescription camera;
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const SizedBox(height: 30),
RaisedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => TakePictureScreen(camera: this.camera))
);
},
child: const Text('Enabled Button', style: TextStyle(fontSize: 20)),
),
],
),
);
}
}
我的问题是,当我启动应用程序并点击按钮时,它会将我带到相机屏幕,但相机无法工作。我如何需要通过 firstCamera 才能使其工作?
谢谢。
【问题讨论】:
标签: android flutter dart camera