Hello I am trying to debug the code below so I have inserted print statements to print to my console so I can pinpoint where my code is crashing.
When I add the first print statement it tells me that it "expected to find ']'" but I have not used any new square brackets. when I take out the first print statement this error goes away.
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
class CameraPage extends StatefulWidget {
final List<CameraDescription>? cameras;
const CameraPage({this.cameras, Key? key}) : super(key: key);
@override
_CameraPageState createState() => _CameraPageState();
}
class _CameraPageState extends State<CameraPage> {
late CameraController controller;
XFile? pictureFile;
@override
void initState() {
super.initState();
controller = CameraController(
widget.cameras![0],
ResolutionPreset.max,
);
controller.initialize().then((_) {
if (!mounted) {
return;
}
setState(() {});
});
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
if (!controller.value.isInitialized) {
return const SizedBox(
child: Center(
child: CircularProgressIndicator(),
),
);
}
return Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Center(
child: SizedBox(
height: 400,
width: 400,
child: CameraPreview(controller),
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: () async {
pictureFile = await controller.takePicture();
setState(() {});
},
child: const Text('Capture Image'),
),
),
print("Passed Test 1");
if (pictureFile != null)
print("Passed Test 2");
Image.network(
pictureFile!.path,
height: 200,
)
//Image.file(File(pictureFile!.path))
//Android/iOS
// Image.file(File(pictureFile!.path)))
],
);
}
}
CodePudding user response:
You cannot add print statemnt directly inside a widget. For example you added a print statement inside a column widget. A column can only hold widgets in its children property but print is not a widget. If you wish to add a print inside a Column widget use a builder
Builder(
builder: (BuildContext context) {
print("msg here");
return SizedBox.shrink();
}
),