I am working on a flutter app.
The widgets are not rendering on the screen.
Here’s the problamatic code:
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
title: const Text("Let's get productive!"),
),
body: Material(
child: Column(
children: [
Pomodoro(),
],
),
),
bottomNavigationBar: BottomNavigationBar(
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
//backgroundColor:
),
BottomNavigationBarItem(
icon: Icon(Icons.analytics),
label: 'Home',
//backgroundColor:
),
BottomNavigationBarItem(
icon: Icon(Icons.settings),
label: 'Home',
//backgroundColor:
),
],
),
),
);
}
}
The Pomodoro class
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [Color(0xff1542bf), Color(0xff51a8ff)],
begin: FractionalOffset(0.5, 1),
),
),
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Padding(
padding: EdgeInsets.all(12.0),
child: Text(
"Pomodoro",
style: TextStyle(
color: Colors.white,
fontSize: 30.0,
),
),
),
const SizedBox(
height: 20.0,
),
Expanded(
child: CircularPercentIndicator(
radius: 250.0,
percent: percent,
animation: true,
animateFromLastPercent: true,
lineWidth: 20.0,
progressColor: Colors.white,
backgroundWidth: 50.0,
center: Text(
"$timeInMinute",
style: const TextStyle(
color: Colors.white,
fontSize: 80.0,
),
),
),
),
const SizedBox(
height: 20.0,
),
],
),
),
);
}
}
I have tried changing the height and width of the container, removing the scaffold and just returning the container, and removing the container just keeping the column in the scaffold body and removing the expanded widget. No matter what I do, I get the same error. Kindly help me.
3
Answers
There are a few issues with your code.
The error is saying your widget is overflowing on the bottom, so you need to make your page scrollable. You can change your column to a
ListView
instead:Your container in
Pomodoro()
doesn’t have a height parameter, which is causing renderbox issues.You need to remove some widgets to make your above code work.
Firstly, remove the Scaffold widget from Pomodoro class.
Lastly, remove the Expanded Widget from your CircularPercentIndicator. It will fix your error. Check below code for Pomodoro class.
If you want your Pomodoro widget to take up the whole screen just wrap the container with an Expanded widget.
Here is a revised tested and working code.