I am getting the following error while expecting the method buildSplashScreen() to return image:
D/MediaScannerConnection(10257): Scanned /storage/emulated/0/Android/data/com.fluttershare.fluutershare/files/Pictures/e1c7909c-9c92-42c1-a7b4-1155b56931267294677592146716356.jpg to null
════════ Exception caught by widgets library ═══════════════════════════════════ The following assertion was thrown building Upload(dirty, dependencies: [_LocalizationsScope-[GlobalKey#50363]], state: _UploadState#dc89a): A build function returned null. >
This is my code below:
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:image_picker/image_picker.dart';
class Upload extends StatefulWidget {
@override
_UploadState createState() => _UploadState();
}
class _UploadState extends State<Upload> {
final ImagePicker _picker = ImagePicker();
PickedFile file;
handleTakePhoto() async {
Navigator.pop(context);
PickedFile file = await _picker.getImage(
source: ImageSource.camera, maxHeight: 675, maxWidth: 900);
setState(() {
this.file = file;
});
return file;
}
handleChooseFromGallery() async {
Navigator.pop(context);
file = await _picker.getImage(source: ImageSource.gallery);
setState(() {
this.file = file;
});
return file;
}
selectImage(parentContext) {
return showDialog(
context: parentContext,
builder: (context) {
return SimpleDialog(
title: Text('Create Post'),
children: <Widget>[
SimpleDialogOption(
child: Text('Photo with Camera'),
onPressed: handleTakePhoto,
),
SimpleDialogOption(
child: Text('Photo from Gallery'),
onPressed: handleChooseFromGallery,
),
SimpleDialogOption(
child: Text('Cancel'),
onPressed: () => Navigator.pop(context),
),
],
);
});
}
Container buildSplashScreen() {
return Container(
color: Colors.indigo,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SvgPicture.asset(
'assets/images/upload.svg',
height: 260.0,
),
Padding(
padding: EdgeInsets.only(top: 20.0),
child: ElevatedButton(
child: Text(
"Upload Imgae",
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
),
onPressed: () => selectImage(context)),
),
]),
);
}
buildUploadForm() {
Text('File loaded');
}
@override
Widget build(BuildContext context) {
return file == null ? buildSplashScreen() : buildUploadForm();
}
}
CodePudding user response:
Add return
to buildUploadForm
method:
Widget buildUploadForm() {
return Text('File loaded');
}