Can you tell me how can I include the condition for Image.file on the following page? I would like to build it only when controller.image is not null.
I got an error: The following NoSuchMethodError was thrown building Container(padding: EdgeInsets.all(32.0)): The method '[]' was called on null. Receiver: null Tried calling:
when I first redirect to this page (and controller.image is null):
class HomePage extends GetView<HomeController> {
final myController1 = TextEditingController();
final myController2 = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Grobonet'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: <Widget>[
TextField(
controller: myController1,
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Nazwisko'),
),
TextField(
controller: myController2,
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Miejscowosc'),
),
IconButton(
icon: Icon(
Icons.add,
size: 30,
),
onPressed: () =>
Get.toNamed(
AppRoutes.PICK_IMAGE
),
color: Colors.pink,
),
IconButton(
icon: Icon(
Icons.save_outlined,
size: 30,
),
/*onPressed: () =>
Get.toNamed(
AppRoutes.PICK_IMAGE
),*/
color: Colors.pink,
),
Container(
padding: EdgeInsets.all(32),
child: GetBuilder<HomeController>(
builder: (_) {
return Image.file(controller.image);
},
),
),
]
),
),
);
}
}
Controller:
class HomeController extends GetxController {
final image = Get.arguments['image'];
final file_loaded = Get.arguments['file_loaded'];
}