'Navigate to new page once upload is done
i'd like to naviagte to a new page to display the uploaded image , I've created custom function 'navigateToNewPage' to navigate , but I get this error
This expression has a type of 'void' so its value can't be used. Try checking to see if you're using the correct API; there might be a function or call that returns void you didn't expect. Also check type parameters and variables which might also be void.
code :
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: Text("Pick Image Camera"),
backgroundColor: Colors.green,
),
body: Center(
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Card(
child: (imageFile == null)
? Text("Choose Image")
: navigateToNewPage() // here's the problem
,
),
MaterialButton(
textColor: Colors.white,
color: Colors.pink,
onPressed: () {
_showChoiceDialog(context);
},
child: Text("Select Image"),
)
],
),
),
),
);
}
void _openGallery(BuildContext context) async {
final pickedFile = await ImagePicker().getImage(
source: ImageSource.gallery,
);
setState(() {
imageFile = pickedFile!;
});
Navigator.pop(context);
}
void _openCamera(BuildContext context) async {
final pickedFile = await ImagePicker().getImage(
source: ImageSource.camera,
);
setState(() {
imageFile = pickedFile!;
});
Navigator.pop(context);
}
void navigateToNewPage() {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => second()),
);
}
Solution 1:[1]
The error message tells you the problem:
- "Card()" is expecting a widget argument for "child".
- Your method, "navigateToNewPage()", is a void function - it doesn't return anything.
- Change "navigateToNewPage()" to return a widget; or - better - modify your code so that your app simply goes to a new page as soon as you've picked a file.
PS: Here's a tutorial - with some example code - that might help:
Flutter Image Picker : How to pick image from Gallery or Camera and Display it?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | paulsm4 |
