I was able to run my code perfectly, but after I added a gesture detector and put a navigtor.pop(), weird exceptions started to face my to-do app.
First here is the code that's causing the problem:
import 'package:flutter/material.dart';
class Task extends StatefulWidget {
static const Routename = '/Task';
@override
TaskState createState() => TaskState();
}
class TaskState extends State<Task> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
child: Column(children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 24),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
GestureDetector(
onTap: () {
Navigator.pop(context);
},
),
Padding(padding: EdgeInsets.all(24)),
Image(image: AssetImage('assets/images/back_arrow_icon.png')),
Expanded(
child: TextField(
decoration: InputDecoration(
hintText: ' Enter your New Task',
hintStyle: TextStyle(fontSize: 18, color: Colors.grey),
border: InputBorder.none),
))
],
),
),
]))));
}
}
I also faced a flutter error which is this:
enter image description here
And a Rendering exception that says:
The following assertion was thrown during performLayout(): RenderPointerListener object was given an infinite size during layout.
Any suggestions on how to fix my code?
CodePudding user response:
It's because you didn't wrapped your GestureDetector around another widget (child) like this:
GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Image(image: AssetImage('assets/images/back_arrow_icon.png')),
),
CodePudding user response:
If GestureDetector does not have a child, it grows to fit the parent instead.
By default a GestureDetector with an invisible child ignores touches.
Try adding a child to GestureDetector.
GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Text('Back'),
),
