Uneven widget's width even with hard coded width in flutter - flutter

I am creating a form with simple labels and input field . Below is the layout code
child: Column(
children: [
Row(
children: [
Padding(
padding: const EdgeInsets.fromLTRB(16,8,0,0),
child: Text(
"Purchase Order : Other Details",
textAlign: TextAlign.start,
style: TextStyle(
color: Colors.black,
fontSize: 22,
fontFamily: 'Lato',
fontWeight: FontWeight.bold),
),
),
],
),
Container(
height: 20,
),
Row(
children: [
Container(
width: 150,
child: Text(
'Gate In Date'.toUpperCase(),
textAlign: TextAlign.end,
style: TextStyle(
color: Colors.black87,
fontSize: 16,
fontFamily: 'Lato',
),
),
),
Padding(
padding: const EdgeInsets.only(left:8,top: 8),
child: Card(
elevation: 5,
borderOnForeground: true,
color: Colors.white,
child: Container(
width: 240,
child: TextFormField(
style: TextStyle(color: Colors.black87),
decoration: InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.only(
left: 16, right: 16)),
),
),
),
),
Container(
width: 150,
child: Text(
'Gate Out Date'.toUpperCase(),
textAlign: TextAlign.end,
style: TextStyle(
color: Colors.black87,
fontSize: 16,
fontFamily: 'Lato',
),
),
),
Padding(
padding: const EdgeInsets.only(left:8,top: 8),
child: Card(
elevation: 5,
borderOnForeground: true,
color: Colors.white,
child: Container(
width: 240,
child: TextFormField(
style: TextStyle(color: Colors.black87),
decoration: InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.only(
left: 16, right: 16)),
),
),
),
)
],
mainAxisAlignment: MainAxisAlignment.start,),
Row(
children: [
Container(
width: 150,
child: Text(
'Gate In Time'.toUpperCase(),
textAlign: TextAlign.end,
style: TextStyle(
color: Colors.black87,
fontSize: 16,
fontFamily: 'Lato',
),
),
),
Padding(
padding: const EdgeInsets.only(top: 8,left: 8),
child: Container(
width: 240,
child: Card(
elevation: 5,
borderOnForeground: true,
color: Colors.white,
child: TextFormField(
style: TextStyle(color: Colors.black87),
decoration: InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.only(
left: 16, right: 16)),
),
),
),
),
Container(
width: 150,
child: Text(
'Gate Out Time'.toUpperCase(),
textAlign: TextAlign.end,
style: TextStyle(
color: Colors.black87,
fontSize: 16,
fontFamily: 'Lato',
),
),
),
Padding(
padding: const EdgeInsets.only(left:8,top: 8),
child: Card(
elevation: 5,
borderOnForeground: true,
color: Colors.white,
child: Container(
width: 240,
child: TextFormField(
style: TextStyle(color: Colors.black87),
decoration: InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.only(
left: 16, right: 16)),
),
),
),
)
],mainAxisAlignment: MainAxisAlignment.start,
),
Padding(
padding: const EdgeInsets.only(top:8.0),
child: Row(mainAxisAlignment: MainAxisAlignment.start
,children: [
Container(
width: 150,
child: Text(
'Tare Weight'.toUpperCase(),
textAlign: TextAlign.end,
style: TextStyle(
color: Colors.black87,
fontSize: 16,
fontFamily: 'Lato',
),
),
),
Row(
children: [
Padding(
padding:
const EdgeInsets.only(top: 8,left: 8),
child: Container(
width: 240,
child: Row(
children: [
Expanded(
child: Card(
elevation: 5,
borderOnForeground: true,
color: Colors.white,
child: TextFormField(
style: TextStyle(
color: Colors.black87),
decoration: InputDecoration(
border: InputBorder.none,
contentPadding:
EdgeInsets.only(
left: 16,
right: 16)),
),
),flex: 2,
),
Expanded(
child: Card(
elevation: 5,
borderOnForeground: true,
color: Colors.white,
child: TextFormField(
style: TextStyle(
color: Colors.black87),
decoration: InputDecoration(
border: InputBorder.none,
contentPadding:
EdgeInsets.only(
left: 16,
right: 16)),
),
),flex: 1,
)
],
),
),
),
],
),
Container(
width: 150,
child: Text(
'Gross Weight'.toUpperCase(),
textAlign: TextAlign.end,
style: TextStyle(
color: Colors.black87,
fontSize: 16,
fontFamily: 'Lato',
),
),
),
Padding(
padding: const EdgeInsets.only(top: 8,left: 8),
child: Container(
width: 240,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Expanded(
child: Card(
elevation: 5,
borderOnForeground: true,
color: Colors.white,
child: TextFormField(
style: TextStyle(
color: Colors.black87),
decoration: InputDecoration(
border: InputBorder.none,
contentPadding:
EdgeInsets.only(
left: 16,
right: 16,
)),
),
),flex: 2,
),
Expanded(
child: Card(
elevation: 5,
borderOnForeground: true,
color: Colors.white,
child: TextFormField(
style: TextStyle(
color: Colors.black87),
decoration: InputDecoration(
border: InputBorder.none,
contentPadding:
EdgeInsets.only(
left: 16,
right: 16,
)),
),
),flex: 1,
)
],
),
),
),
],
),
),
Row(mainAxisAlignment: MainAxisAlignment.start
,children: [
Container(
width: 150,
child: Text(
''.toUpperCase(),
textAlign: TextAlign.end,
style: TextStyle(
color: Colors.black87,
fontSize: 16,
fontFamily: 'Lato',
),
),
),
Container(
width: 240,
child: Text(''),
),
Padding(
padding:
const EdgeInsets.only(left: 8),
child: Container(
width: 150,
child: Text(
'Net Weight'.toUpperCase(),
textAlign: TextAlign.end,
style: TextStyle(
color: Colors.black87,
fontSize: 16,
fontFamily: 'Lato',
),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 8),
child: Container(
width: 240,
child: Row(mainAxisAlignment: MainAxisAlignment.start
,children: [
Expanded(
child: Card(
elevation: 5,
borderOnForeground: true,
color: Colors.white,
child: TextFormField(
style: TextStyle(
color: Colors.black87),
decoration: InputDecoration(
border: InputBorder.none,
contentPadding:
EdgeInsets.only(
left: 16,
right: 16,
)),
),
),flex: 2,
),
Expanded(
child: Card(
elevation: 5,
borderOnForeground: true,
color: Colors.white,
child: TextFormField(
style: TextStyle(
color: Colors.black87),
decoration: InputDecoration(
border: InputBorder.none,
contentPadding:
EdgeInsets.only(
left: 16,
right: 16,)),
),
),flex: 1,
)
],
),
),
),
],
),
],
)
For every label and input field, I have given same fixed width but still they are not looking equal when I run the app in device
See the attached screenshot

Why don't you structure it the other way around Row(Column(), Column, Column, Column)
1st column labels, 2nd fields, 3rd labels, 4th fields

Related

How to Place Text Widget at the Bottom of Flutter Page?

I have an application like this:
I want to place a Text widget at the bottom of the page. How can I do that?
Codes:
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:teen_browser/pages/LoginAndRegister/LoginPage.dart';
import 'package:teen_browser/pages/LoginAndRegister/RegisterPage.dart';
class RegisterPage extends StatelessWidget {
const RegisterPage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color.fromARGB(255, 25, 25, 25),
body: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: MediaQuery.of(context).size.height * 0.05,
),
Center(
child: Image.asset("assets/Logo.png", height: MediaQuery.of(context).size.height * 0.1),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.07,
),
const Padding(
padding: EdgeInsets.only(left: 15),
child: Text("Ad:", style: TextStyle(fontSize: 20, color: Colors.white)),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.01,
),
Padding(
padding: EdgeInsets.only(left: 15, right: 15),
child: TextFormField(
style: const TextStyle(color: Colors.white, fontSize: 18, fontFamily: "Montserrat"),
decoration: InputDecoration(
prefixIcon: const Icon(Icons.person),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
),
filled: true,
hintStyle: TextStyle(color: Colors.grey[600], fontFamily: "Montserrat"),
hintText: "Ad",
fillColor: Color.fromARGB(179, 55, 55, 55)
),
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.02,
),
const Padding(
padding: EdgeInsets.only(left: 15),
child: Text("Soyad:", style: TextStyle(fontSize: 20, color: Colors.white)),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.01,
),
Padding(
padding: EdgeInsets.only(left: 15, right: 15),
child: TextFormField(
style: const TextStyle(color: Colors.white, fontSize: 18, fontFamily: "Montserrat"),
decoration: InputDecoration(
prefixIcon: const Icon(Icons.person),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
),
filled: true,
hintStyle: TextStyle(color: Colors.grey[600], fontFamily: "Montserrat"),
hintText: "Soyad",
fillColor: Color.fromARGB(179, 55, 55, 55)
),
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.02,
),
const Padding(
padding: EdgeInsets.only(left: 15),
child: Text("E-Posta:", style: TextStyle(fontSize: 20, color: Colors.white)),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.01,
),
Padding(
padding: EdgeInsets.only(left: 15, right: 15),
child: TextFormField(
style: const TextStyle(color: Colors.white, fontSize: 18, fontFamily: "Montserrat"),
decoration: InputDecoration(
prefixIcon: const Icon(Icons.mail),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
),
filled: true,
hintStyle: TextStyle(color: Colors.grey[600], fontFamily: "Montserrat"),
hintText: "E-Posta",
fillColor: const Color.fromARGB(179, 55, 55, 55)
),
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.02,
),
const Padding(
padding: EdgeInsets.only(left: 15),
child: Text("Parola:", style: TextStyle(fontSize: 20, color: Colors.white)),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.01,
),
Padding(
padding: const EdgeInsets.only(left: 15, right: 15),
child: TextFormField(
style: const TextStyle(color: Colors.white, fontSize: 18, fontFamily: "Montserrat"),
decoration: InputDecoration(
prefixIcon: const Icon(Icons.lock),
prefixIconColor: const Color.fromARGB(255, 162, 162, 162),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
),
filled: true,
hintStyle: TextStyle(color: Colors.grey[600], fontFamily: "Montserrat"),
prefixStyle: TextStyle(color: Colors.grey[600]),
hintText: "Parola",
fillColor: const Color.fromARGB(179, 55, 55, 55)
),
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.03,
),
Padding(
padding: const EdgeInsets.only(left: 15, right: 15),
child: Center(
child: Container(
width: MediaQuery.of(context).size.width * 0.8,
height: MediaQuery.of(context).size.height * 0.05,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: const Color.fromARGB(255, 47, 47, 47),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16), // <-- Radius
),
),
child: const Text("Hesap OluลŸtur", style: TextStyle(color: Colors.white, fontSize: 20, fontFamily: "Montserrat")),
onPressed: () {},
),
),
),
),
],
),
),
);
}
}
I tried with code like this:
Align(
alignment: Alignment.bottomCenter,
child: Text("Test"),
),
But this code didn't work. He settled into the regular Column row. It's not at the bottom of the page.
Thanks for help.
Using another column with MainAxisAlignment.spaceBetween, works, also you can replace MediaQuery size with `LayoutBuilder.
class RegisterPage extends StatelessWidget {
const RegisterPage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color.fromARGB(255, 25, 25, 25),
body: LayoutBuilder(
builder: (context, constraints) => SingleChildScrollView(
child: SizedBox(
height: constraints.maxHeight,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: MediaQuery.of(context).size.height * 0.05,
),
Center(
child: Image.asset("assets/Logo.png",
height: MediaQuery.of(context).size.height * 0.1),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.07,
),
const Padding(
padding: EdgeInsets.only(left: 15),
child: Text("Ad:",
style: TextStyle(fontSize: 20, color: Colors.white)),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.01,
),
Padding(
padding: EdgeInsets.only(left: 15, right: 15),
child: TextFormField(
style: const TextStyle(
color: Colors.white,
fontSize: 18,
fontFamily: "Montserrat"),
decoration: InputDecoration(
prefixIcon: const Icon(Icons.person),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
),
filled: true,
hintStyle: TextStyle(
color: Colors.grey[600],
fontFamily: "Montserrat"),
hintText: "Ad",
fillColor: Color.fromARGB(179, 55, 55, 55)),
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.02,
),
const Padding(
padding: EdgeInsets.only(left: 15),
child: Text("Soyad:",
style: TextStyle(fontSize: 20, color: Colors.white)),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.01,
),
Padding(
padding: EdgeInsets.only(left: 15, right: 15),
child: TextFormField(
style: const TextStyle(
color: Colors.white,
fontSize: 18,
fontFamily: "Montserrat"),
decoration: InputDecoration(
prefixIcon: const Icon(Icons.person),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
),
filled: true,
hintStyle: TextStyle(
color: Colors.grey[600],
fontFamily: "Montserrat"),
hintText: "Soyad",
fillColor: Color.fromARGB(179, 55, 55, 55)),
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.02,
),
const Padding(
padding: EdgeInsets.only(left: 15),
child: Text("E-Posta:",
style: TextStyle(fontSize: 20, color: Colors.white)),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.01,
),
Padding(
padding: EdgeInsets.only(left: 15, right: 15),
child: TextFormField(
style: const TextStyle(
color: Colors.white,
fontSize: 18,
fontFamily: "Montserrat"),
decoration: InputDecoration(
prefixIcon: const Icon(Icons.mail),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
),
filled: true,
hintStyle: TextStyle(
color: Colors.grey[600],
fontFamily: "Montserrat"),
hintText: "E-Posta",
fillColor: const Color.fromARGB(179, 55, 55, 55)),
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.02,
),
const Padding(
padding: EdgeInsets.only(left: 15),
child: Text("Parola:",
style: TextStyle(fontSize: 20, color: Colors.white)),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.01,
),
Padding(
padding: const EdgeInsets.only(left: 15, right: 15),
child: TextFormField(
style: const TextStyle(
color: Colors.white,
fontSize: 18,
fontFamily: "Montserrat"),
decoration: InputDecoration(
prefixIcon: const Icon(Icons.lock),
prefixIconColor:
const Color.fromARGB(255, 162, 162, 162),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
),
filled: true,
hintStyle: TextStyle(
color: Colors.grey[600],
fontFamily: "Montserrat"),
prefixStyle: TextStyle(color: Colors.grey[600]),
hintText: "Parola",
fillColor: const Color.fromARGB(179, 55, 55, 55)),
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.03,
),
Padding(
padding: const EdgeInsets.only(left: 15, right: 15),
child: Center(
child: Container(
width: MediaQuery.of(context).size.width * 0.8,
height: MediaQuery.of(context).size.height * 0.05,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16), // <-- Radius
),
),
child: const Text("Hesap OluลŸtur",
style: TextStyle(color: Colors.white, fontSize: 20, fontFamily: "Montserrat")),
onPressed: () {},
),
),
),
),
],
),
Text("dsadas"),
],
),
),
),
),
);
}
}

Flutter remove extra space left and right of appbar

So I have been trying to work around this but couldn't I have a search box inside my appbar in flutter and I have a PreferredSize to help with the height my I have extra space as shown with the blue line in the image below. Can someone help on how to remove this padding-like space as I want the content to align with the content below the search box? Below is the screenshot and my code snippet.
appBar: PreferredSize(
preferredSize: Size.fromHeight(40.0),
// here the desired height
child: AppBar(
centerTitle: true,
backgroundColor: colorGreen,
title: Container(
height: 35,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
),
child: Center(
child: SizedBox(
height: 40,
width: double.infinity,
child: Row(
children: <Widget>[
// Expanded(
Container(
padding: EdgeInsets.only(bottom:6),
width: 240,
alignment: Alignment.centerLeft,
child: TextField(
readOnly: true,
onTap: (){
},
textAlign: TextAlign.left,
controller: controller,
cursorColor: Colors.grey,
style: TextStyle(
color: Colors.grey,
fontSize: 16,
fontFamily: 'Montserrat'),
onChanged:
onSearchTextChanged,
decoration: InputDecoration(
hintText: "Search",
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 13,fontWeight: FontWeight.normal,
fontFamily:
'Montserrat'),
border: InputBorder.none,
prefixIcon: Container(
padding: EdgeInsets.only(top: 5),
child:Icon(
Icons.search,
color: Colors.grey,
size: 15,
)),
suffixIcon: Visibility(
visible: backClear,
child:InkWell(
onTap: () {
},
child: Container(
padding: EdgeInsets.only(top: 5),
child:Icon(
Icons.backspace,
color: Colors.grey,
size: 12,
)))),
labelStyle: TextStyle(
color: Colors.grey,
fontSize: 14,fontWeight: FontWeight.normal,
fontFamily:
'Montserrat'),
// hintText:Center(child: Text(""),), //contentPadding: EdgeInsets.only(top: 2),
),
),
),
new Container(
width: 2.0,
height: 100.0,
color: colorGreen,
),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.center,
child: new Theme(
data: Theme.of(context)
.copyWith(
canvasColor:colorGray,
),
child:Directionality(
textDirection: TextDirection.ltr,
child: DropdownButtonHideUnderline(
child: ButtonTheme(
alignedDropdown: true,
child: DropdownButton(
//iconSize: 15,
isDense: false,
icon: Container(
padding: EdgeInsets.all(0),
child:Icon(
//Icons.arrow_drop_down,
Icons.location_on,
color: Colors.grey,
size: 15,
)),
hint: Center(
child: Text(
"All Cities",
textAlign: TextAlign
.center,
style: TextStyle(
color: Colors
.grey,
fontWeight:
FontWeight
.normal,
fontFamily:
'Montserrat',
fontSize: 12),
)),
style: TextStyle(
color: Colors
.grey,
fontWeight:
FontWeight
.normal,
fontFamily:
'Montserrat',
fontSize: 12),
//value: selectedCountry,
onChanged: (newVal) {
setState(() {
});
},
value: _mySelection,
items:
data.map((item) {
return new DropdownMenuItem(
child: Container(
child: Container(
padding: EdgeInsets.all(0),
child: Center(
child: Text(
""
))),
),
value: item['id']
.toString(),
);
}).toList(),
isExpanded: true,
),
),
)
),
)
),
)
],
),
))),
),
),
Add titleSpacing 0 and automaticallyImplyLeading false as below:
AppBar(
automaticallyImplyLeading: false,
titleSpacing: 0
)
Note: It will remove leading icon , you can add your own custom Leading icon.
Make center title to false and add leadingWidth: 0,
centerTitle: false,
appBar: PreferredSize(
preferredSize: Size.fromHeight(40.0),
// here the desired height
child: AppBar(
leadingWidth: 0,
centerTitle: true,
backgroundColor: colorGreen,
title: Container(
height: 35,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
),
child: Center(
child: SizedBox(
height: 40,
width: double.infinity,
child: Row(
children: <Widget>[
// Expanded(
Container(
padding: EdgeInsets.only(bottom:6),
width: 240,
alignment: Alignment.centerLeft,
child: TextField(
readOnly: true,
onTap: (){
},
textAlign: TextAlign.left,
controller: controller,
cursorColor: Colors.grey,
style: TextStyle(
color: Colors.grey,
fontSize: 16,
fontFamily: 'Montserrat'),
onChanged:
onSearchTextChanged,
decoration: InputDecoration(
hintText: "Search",
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 13,fontWeight: FontWeight.normal,
fontFamily:
'Montserrat'),
border: InputBorder.none,
prefixIcon: Container(
padding: EdgeInsets.only(top: 5),
child:Icon(
Icons.search,
color: Colors.grey,
size: 15,
)),
suffixIcon: Visibility(
visible: backClear,
child:InkWell(
onTap: () {
},
child: Container(
padding: EdgeInsets.only(top: 5),
child:Icon(
Icons.backspace,
color: Colors.grey,
size: 12,
)))),
labelStyle: TextStyle(
color: Colors.grey,
fontSize: 14,fontWeight: FontWeight.normal,
fontFamily:
'Montserrat'),
// hintText:Center(child: Text(""),), //contentPadding: EdgeInsets.only(top: 2),
),
),
),
new Container(
width: 2.0,
height: 100.0,
color: colorGreen,
),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.center,
child: new Theme(
data: Theme.of(context)
.copyWith(
canvasColor:colorGray,
),
child:Directionality(
textDirection: TextDirection.ltr,
child: DropdownButtonHideUnderline(
child: ButtonTheme(
alignedDropdown: true,
child: DropdownButton(
//iconSize: 15,
isDense: false,
icon: Container(
padding: EdgeInsets.all(0),
child:Icon(
//Icons.arrow_drop_down,
Icons.location_on,
color: Colors.grey,
size: 15,
)),
hint: Center(
child: Text(
"All Cities",
textAlign: TextAlign
.center,
style: TextStyle(
color: Colors
.grey,
fontWeight:
FontWeight
.normal,
fontFamily:
'Montserrat',
fontSize: 12),
)),
style: TextStyle(
color: Colors
.grey,
fontWeight:
FontWeight
.normal,
fontFamily:
'Montserrat',
fontSize: 12),
//value: selectedCountry,
onChanged: (newVal) {
setState(() {
});
},
value: _mySelection,
items:
data.map((item) {
return new DropdownMenuItem(
child: Container(
child: Container(
padding: EdgeInsets.all(0),
child: Center(
child: Text(
""
))),
),
value: item['id']
.toString(),
);
}).toList(),
isExpanded: true,
),
),
)
),
)
),
)
],
),
))),
),
),
You can replace the title with flexibleSpace
AppBar(
centerTitle: true,
backgroundColor: Colors.green,
flexibleSpace: Container(
// height: 35, <-- adjust height here
margin: EdgeInsets.zero,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
),
child: Center(
....
)
),
)

How to add scroll on visibility on flutter

i want to make scrollview in visibility but when i try to add SingleChildScrollView it still doesn't work, the result is like this
This is the result
and what I want the application will run as shown below
its main purpose is when the DropdownMenuItem is scrolled on the screen it will not be carried away
thank you, sorry if my words are a little difficult to understand
and this is my code:
class AddressScreen extends StatefulWidget {
#override
State<StatefulWidget> createState() => _AddressState();
}
class _AddressState extends State<AddressScreen> {
String? _detail;
bool _saveButton = false;
String? valueChoose;
List listProvinsi = ['Lampung', 'DKI Jakarta'];
String? valueChoose2;
List listKabupaten = ['Bandar Lampung', 'Jakarta Timur'];
String? valueChoose3;
List listKecamatan = ['Kemiling', 'Cipayung'];
String? valueChoose4;
List listKelurahan = ['Beringin Raya', 'Bambu Apus'];
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[100],
appBar: AppBar(
titleSpacing: 0,
elevation: 10,
backgroundColor: Theme.of(context).primaryColor,
title: Text(
'Alamat',
style: TextStyle(fontSize: 18),
),
actions: [
GestureDetector(
onTap: () => {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ProfileScreen(),
),
),
},
child: Container(
height: 30,
width: 30,
margin: EdgeInsets.only(
right: 3,
),
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(color: Colors.white, width: 1.5),
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage(personImg),
),
),
),
),
GestureDetector(
onTap: () => {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomeScreen(),
),
),
},
child: Container(
margin: EdgeInsets.only(
right: 7,
),
child: Image.asset(iconAppbar),
),
),
],
),
body: SafeArea(
child: Container(
child: Column(
children: <Widget>[
Container(
height: SizeConfig.screenHeight / 4.5,
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Color(0x14000000),
offset: Offset(
0,
2,
),
blurRadius: 4,
spreadRadius: 2,
),
],
),
child: Row(
children: [
SizedBox(width: SizeConfig.screenWidth / 17),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 15),
Container(
child: Text(
'Alamat Anda',
style: TextStyle(
color: Colors.grey.shade700,
fontSize: 14,
fontWeight: FontWeight.bold,
),
),
),
Container(
height: SizeConfig.screenHeight / 9,
width: SizeConfig.screenWidth / 2.2,
// color: Colors.grey,
child: Row(
children: [
Expanded(
child: Text(
'Perumahan Berkoh Indah Jl. Brawijaya No. 45 Gg. Mangga Rt.03 Rw.05 Kel. Arcawinangun, Kec. Purwokerto Timur, Kab. Banyumas Jawa Tengah - 53114',
style: TextStyle(
color: Colors.black54,
fontSize: 11,
),
),
),
],
),
)
],
),
SizedBox(width: SizeConfig.screenWidth / 9),
//#arjunalst2020
// ChangeButton(),
InkWell(
onTap: () {
setState(() {
_saveButton = !_saveButton;
});
},
child: Container(
margin:
EdgeInsets.only(top: SizeConfig.screenHeight / 8),
height: SizeConfig.screenHeight / 17,
width: SizeConfig.screenWidth / 3,
decoration: _saveButton
? BoxDecoration(
color: Colors.grey.shade700,
borderRadius:
BorderRadius.all(Radius.circular(8)))
: BoxDecoration(
color: Colors.pink.shade800,
borderRadius:
BorderRadius.all(Radius.circular(8))),
child: Center(
child: Text(
_saveButton ? 'Simpan' : 'Ubah',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white),
),
),
),
),
],
),
),
SizedBox(height: 20),
Visibility(
visible: _saveButton,
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 23),
child: Text(
'Provinsi',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black87,
fontSize: 12,
),
),
),
SizedBox(height: 3),
Center(
child: Padding(
padding: const EdgeInsets.only(right: 20, left: 20),
child: Container(
height: SizeConfig.screenHeight / 17,
padding: EdgeInsets.only(right: 10, left: 10),
decoration: BoxDecoration(
color: Colors.grey.shade300,
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
child: DropdownButton(
isExpanded: true,
dropdownColor: Colors.white,
value: valueChoose,
iconSize: 25,
underline: SizedBox(),
style: TextStyle(
fontSize: 13,
color: Colors.black54,
fontWeight: FontWeight.bold),
onChanged: (newValue) {
setState(() {
valueChoose = newValue.toString();
});
},
items: listProvinsi.map((valueItem) {
return DropdownMenuItem(
value: valueItem, child: Text(valueItem));
}).toList(),
),
),
),
),
SizedBox(height: 30),
Container(
margin: EdgeInsets.only(left: 23),
child: Text(
'Kabupaten/Kota',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black87,
fontSize: 12,
),
),
),
SizedBox(height: 3),
Center(
child: Padding(
padding: const EdgeInsets.only(right: 20, left: 20),
child: Container(
height: SizeConfig.screenHeight / 17,
padding: EdgeInsets.only(right: 10, left: 10),
decoration: BoxDecoration(
color: Colors.grey.shade300,
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
child: DropdownButton(
isExpanded: true,
dropdownColor: Colors.white,
value: valueChoose2,
iconSize: 25,
underline: SizedBox(),
style: TextStyle(
fontSize: 13,
color: Colors.black54,
fontWeight: FontWeight.bold),
onChanged: (newValue2) {
setState(() {
valueChoose2 = newValue2.toString();
});
},
items: listKabupaten.map((valueItem) {
return DropdownMenuItem(
value: valueItem, child: Text(valueItem));
}).toList(),
),
),
),
),
SizedBox(height: 30),
Container(
margin: EdgeInsets.only(left: 23),
child: Text(
'Kecamatan',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black87,
fontSize: 12,
),
),
),
SizedBox(height: 3),
Center(
child: Padding(
padding: const EdgeInsets.only(right: 20, left: 20),
child: Container(
height: SizeConfig.screenHeight / 17,
padding: EdgeInsets.only(right: 10, left: 10),
decoration: BoxDecoration(
color: Colors.grey.shade300,
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
child: DropdownButton(
isExpanded: true,
dropdownColor: Colors.white,
value: valueChoose3,
iconSize: 25,
underline: SizedBox(),
style: TextStyle(
fontSize: 13,
color: Colors.black54,
fontWeight: FontWeight.bold),
onChanged: (newValue3) {
setState(() {
valueChoose3 = newValue3.toString();
});
},
items: listKecamatan.map((valueItem) {
return DropdownMenuItem(
value: valueItem, child: Text(valueItem));
}).toList(),
),
),
),
),
SizedBox(height: 30),
Container(
margin: EdgeInsets.only(left: 23),
child: Text(
'Kelurahan',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black87,
fontSize: 12,
),
),
),
SizedBox(height: 3),
Center(
child: Padding(
padding: const EdgeInsets.only(right: 20, left: 20),
child: Container(
height: SizeConfig.screenHeight / 17,
padding: EdgeInsets.only(right: 10, left: 10),
decoration: BoxDecoration(
color: Colors.grey.shade300,
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
child: DropdownButton(
isExpanded: true,
dropdownColor: Colors.white,
value: valueChoose4,
iconSize: 25,
underline: SizedBox(),
style: TextStyle(
fontSize: 13,
color: Colors.black54,
fontWeight: FontWeight.bold,
),
onChanged: (newValue4) {
setState(() {
valueChoose4 = newValue4.toString();
});
},
items: listKelurahan.map((valueItem) {
return DropdownMenuItem(
value: valueItem, child: Text(valueItem));
}).toList(),
),
),
),
),
SizedBox(height: 30),
Container(
margin: EdgeInsets.only(left: 23),
child: Text(
'Jalan/Gang/Nama Gedung/Nama Perumahan',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black87,
fontSize: 12,
),
),
),
SizedBox(height: 3),
Center(
child: Container(
height: SizeConfig.screenHeight / 17,
width: SizeConfig.screenWidth / 1.12,
child: TextField(
maxLines: 1,
style: TextStyle(fontSize: 12),
onChanged: (value) {
setState(() {
_detail = value;
});
},
decoration: InputDecoration(
counterText: "",
fillColor: Colors.grey.shade300,
filled: true,
border: OutlineInputBorder(
borderSide: BorderSide.none,
),
),
),
),
),
SizedBox(height: 30),
Container(
margin: EdgeInsets.only(left: 23),
child: Text(
'Unit/Blok/RT/RW',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black87,
fontSize: 12,
),
),
),
SizedBox(height: 3),
Center(
child: Container(
height: SizeConfig.screenHeight / 17,
width: SizeConfig.screenWidth / 1.12,
child: TextField(
maxLines: 1,
style: TextStyle(fontSize: 12),
onChanged: (value) {
setState(() {
_detail = value;
});
},
decoration: InputDecoration(
fillColor: Colors.grey.shade300,
filled: true,
border: OutlineInputBorder(
borderSide: BorderSide.none,
),
),
),
),
),
SizedBox(height: 30),
Container(
margin: EdgeInsets.only(left: 23),
child: Text(
'Kode Pos',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black87,
fontSize: 12,
),
),
),
SizedBox(height: 3),
Center(
child: Container(
height: SizeConfig.screenHeight / 17,
width: SizeConfig.screenWidth / 1.12,
child: TextField(
keyboardType: TextInputType.number,
maxLines: 1,
maxLength: 8,
style: TextStyle(fontSize: 12),
onChanged: (value) {
setState(() {
_detail = value;
});
},
decoration: InputDecoration(
fillColor: Colors.grey.shade300,
filled: true,
counterText: "",
border: OutlineInputBorder(
borderSide: BorderSide.none,
),
),
),
),
),
SizedBox(height: 30),
Center(
child: Container(
width: SizeConfig.screenWidth / 1.12,
height: SizeConfig.screenHeight / 10,
decoration: BoxDecoration(
color: Colors.transparent,
border:
Border.all(color: Colors.black38, width: 0.6),
),
child: Row(
children: [
Container(
height: SizeConfig.screenHeight,
width: SizeConfig.screenWidth / 5,
decoration: BoxDecoration(
color: Colors.blueGrey,
),
child: Icon(
Icons.location_on,
color: Colors.white,
size: 35,
),
),
SizedBox(width: SizeConfig.screenWidth / 20),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 10),
Text(
'Tandai Lokasi Peta',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black87,
fontSize: 11,
),
),
Container(
height: SizeConfig.screenHeight / 17,
width: SizeConfig.screenWidth / 1.9,
child: Row(
children: [
Expanded(
child: Text(
'Jl. Brawijaya No,45 Gg. Mangga Kel. Arcawinangun, Kec. Purwokerto Timur, Banyumas',
style: TextStyle(
fontSize: 11,
color: Colors.grey.shade800,
),
),
),
],
),
),
],
),
],
),
),
),
SizedBox(height: 10),
Container(
height: SizeConfig.screenHeight / 20,
width: SizeConfig.screenWidth / 1.6,
margin:
EdgeInsets.only(left: SizeConfig.screenWidth / 3.3),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Text(
'Pastikan lokasi yang Anda tandai di peta sesuai dengan alamat yang Anda isi di atas',
style: TextStyle(
fontSize: 9,
color: Colors.grey.shade800,
),
),
),
],
),
),
SizedBox(height: 30),
],
),
),
),
],
),
),
),
);
}
}
I'm sorry if my code is still messy or a lot of it is not effective, I'm just learning ๐Ÿ˜…
Wrap the Visibility widget with Expanded.
Expanded(
child: Visibility(
.....
),
),
If this doesn't work, wrap the main body Column with SingleChildScrollView.
NOTE: Wrapping the main Column with a Container is unnecessary.
I had the same issue multiple times.
you need to wrap your SingleChildScrollView in a Flexible.
Here is the sequence I need to do to always fix:
Flexible(
child: SingleChildScrollView(
child: Form(
key: _formKey,
child: Column(
children:[Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.only(left:10, top: 20, bottom: 20),
child: Text( )

I want to control the texteditingcontroller for each of the IngredientContainers' so that i can display it on my screen

Instead all of them being Hello i want each of them to be individually typed in and different val
Here's the code:
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:recipe_saver/Screens/saver_recipes.dart';
class RecipeEditorScreen extends StatefulWidget {
#override
_RecipeEditorScreenState createState() => _RecipeEditorScreenState();
}
class _RecipeEditorScreenState extends State<RecipeEditorScreen> {
// ignore: non_constant_identifier_names
List IngredientContainer = [];
final textFieldEdit = TextEditingController();
TextEditingController IngredientSaver = TextEditingController();
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
Container(
height: MediaQuery
.of(context)
.size
.height,
width: MediaQuery
.of(context)
.size
.width,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.blueGrey, Colors.blueGrey[900]])),
),
Container(
padding: EdgeInsets.symmetric(
vertical: Platform.isIOS ? 60 : 30, horizontal: 30),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
GestureDetector(
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) =>
saverecipes()));
},
child: Text(
"Recipe",
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w500,
),
),
),
GestureDetector(
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) =>
saverecipes()));
},
child: Text(
"Saver",
style: TextStyle(
color: Colors.blue,
fontSize: 18,
fontWeight: FontWeight.w500,
),
),
),
],
),
),
SizedBox(
height: 30,
),
Stack(
children: [
Container(
margin: EdgeInsets.symmetric(
vertical: Platform.isIOS ? 120 : 90, horizontal: 5),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
gradient: LinearGradient(
colors: [Colors.blue, Colors.blueAccent],
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Row(
children: [
Padding(
padding: EdgeInsets.only(top: 15, left: 5),
child: Text(
"Dish:",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
fontSize: 35,
fontFamily: 'Overpass',
),
),
),
Expanded(
child: Padding(
padding:
EdgeInsets.only(top: 15, right: 5, left: 10),
child: TextField(
controller: textFieldEdit,
cursorColor: Colors.black,
decoration: InputDecoration(
hintText: "Enter Dish Title",
hintStyle: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 25,
color: Colors.grey,
),
enabledBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.blueAccent),
),
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.blueAccent),
)),
style: TextStyle(
fontFamily: 'Overpass',
fontSize: 35,
color: Colors.black,
fontWeight: FontWeight.bold),
),
),
),
],
),
SizedBox(
height: 50,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: EdgeInsets.only(left: 5),
child: Text(
"Ingredients:",
style: TextStyle(
fontWeight: FontWeight.w500,
color: Colors.black,
fontSize: 25,
fontFamily: 'Overpass'),
),
),
IconButton(
icon: Icon(Icons.add_circle_outline,
size: 30, color: Colors.black),
onPressed: () {
setState(() {
IngredientContainer.add('');
});
},
),
],
),
Expanded(
child: Container(
height: double.infinity,
width: MediaQuery
.of(context)
.size
.width,
child: ListView.builder(
itemCount: IngredientContainer.length,
itemBuilder: (context, index) {
return Container(
height: 50,
width: MediaQuery
.of(context)
.size
.width,
child: Row(
children: [
Padding(
padding: EdgeInsets.only(left: 7),
child: Text(
"Ingredient:",
style: TextStyle(
fontWeight: FontWeight.w400,
fontFamily: 'OverPass',
fontSize: 17,
),
),
),
Expanded(
child: Padding(
padding:
EdgeInsets.only(left: 8, right: 8),
child: TextField(
controller: IngredientSaver,
cursorColor: Colors.black,
decoration: InputDecoration(
hintText: 'Type Ingredient
Here',
hintStyle: TextStyle(
fontSize: 17,
fontFamily: 'Overpass',
fontWeight: FontWeight.w200,
color: Colors.grey,
),
enabledBorder:
UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.blueAccent),
),
focusedBorder:
UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.blueAccent),
),
),
style: TextStyle(
fontWeight: FontWeight.w400,
fontFamily: 'Overpass',
fontSize: 17,
color: Colors.black,
),
),
),
),
GestureDetector(
onTap: () {
setState(() {
IngredientContainer.removeAt(index);
});
},
child: Padding(
padding: EdgeInsets.only(right: 7),
child: Container(
child: Icon(Icons.delete),
),
),
)
],
),
);
},
),
),
),
GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.blueGrey,
Colors.blueGrey[900]]
),
borderRadius: BorderRadius.circular(7)
),
child: Padding(
padding: EdgeInsets.all(8.0),
child: Text(
"Enter",
style: TextStyle(
fontSize: 20,
fontFamily: 'Overpass',
fontWeight: FontWeight.w600,
color: Colors.black
),
),
),
),
)
],
),
),
],
),
],
),
);
}
}

FutureBuilder : RangeError (RangeError (index): Invalid value: Valid value range is empty: 0) in Flutter

I've read almost article about this error, but common answers were 'using FutureBuilder' or 'using isEmpty?'. I've tried both solutions, but error still comes up. Thanks in advance.
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:intl/intl.dart';
import 'package:dont_forget/Database/db_prRepeat.dart';
import 'package:dont_forget/Database/pr_repeat.dart';
import 'dart:core';
import 'dart:ui';
import 'dart:async';
class Progress extends StatefulWidget {
#override
_ProgressState createState() => _ProgressState();
}
class _ProgressState extends State<Progress> {
var year = DateFormat('yyyy').format(DateTime.now());
var month = DateFormat('M').format(DateTime.now());
var date = DateFormat('d').format(DateTime.now());
int ticks = 4;
void initState() {
super.initState();
loadPrRepeat();
}
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: false,
resizeToAvoidBottomInset: true,
backgroundColor: Colors.white,
appBar: AppBar(
backgroundColor: Colors.transparent,
bottomOpacity: 0.0,
elevation: 0.0,
title: const Text(
'์ง„ํ–‰ ์ƒํ™ฉ',
style: TextStyle(
fontWeight: FontWeight.w600, color: Colors.black, fontSize: 20),
),
),
body: FutureBuilder(
future: loadPrRepeat(),
builder: (context, snap) {
if (snap.data == null ||
snap.data.length == 0 ||
snap.data.isEmpty) {
return ListView(children: <Widget>[
Container(
padding: EdgeInsets.only(left: 21, right: 30),
child: Text(
"์•„์ง ์ง„ํ–‰๋œ ํ•™์Šต์ด ์—†์Šต๋‹ˆ๋‹ค. \nํ•™์Šต์„ ๋งˆ์น˜๋ฉด ์ง„ํ–‰ ์ƒํ™ฉ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.\n\n์˜ˆ์‹œ)",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
color: Colors.black.withOpacity(0.5)))),
SizedBox(
height: 10,
),
GestureDetector(
onTap: () {},
child: Column(children: <Widget>[
Row(children: <Widget>[
Container(
padding:
EdgeInsets.only(left: 20, right: 115, top: 5),
child: Text("$year๋…„ $month์›” $date์ผ",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w800,
color: Colors.black))),
Container(
padding: EdgeInsets.only(top: 3),
child: Text("๋‹จ์–ด ๋ณด๊ธฐ",
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w400,
color: Colors.black))),
Container(
padding: EdgeInsets.only(top: 2),
child: IconButton(
icon: Icon(Icons.arrow_forward_ios,
color: Colors.black, size: 15),
onPressed: () => {}))
]),
SizedBox(height: 3),
Row(
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 22, top: 3),
child: Text("๋ณต์Šต์™„๋ฃŒ",
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: Colors.black))),
SizedBox(width: 10),
Container(
padding: EdgeInsets.only(top: 6, right: 1.5),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.yellow[600],
),
width: 30.0,
height: 30.0,
child: Text("1",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Colors.black))),
SizedBox(width: 7),
Container(
padding: EdgeInsets.only(top: 6, right: 0.5),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.yellow[600],
),
width: 30.0,
height: 30.0,
child: Text("2",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Colors.black))),
SizedBox(width: 7),
Container(
padding: EdgeInsets.only(top: 6, right: 0.5),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.yellow[600],
),
width: 30.0,
height: 30.0,
child: Text("3",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Colors.black))),
SizedBox(width: 7),
Container(
padding: EdgeInsets.only(top: 6),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.grey[200],
),
width: 30.0,
height: 30.0,
child: Text("6",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Colors.black))),
SizedBox(width: 7),
Container(
padding: EdgeInsets.only(top: 6),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.grey[200],
),
width: 30.0,
height: 30.0,
child: Text("13",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Colors.black))),
SizedBox(width: 7),
Container(
padding: EdgeInsets.only(top: 6),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.grey[200],
),
width: 30.0,
height: 30.0,
child: Text("28",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Colors.black))),
SizedBox(width: 7),
Container(
padding: EdgeInsets.only(top: 6),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.grey[200],
),
width: 30.0,
height: 30.0,
child: Text("58",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Colors.black))),
],
)
]))
]);
} else {
return ListView.builder(
shrinkWrap: true,
itemCount: snap.data.length.compareTo(0),
scrollDirection: Axis.vertical,
itemBuilder: (context, index) {
PrRepeat repeat = snap.data[index];
return GestureDetector(
onTap: () {},
child: Column(children: <Widget>[
Row(children: <Widget>[
Container(
padding: EdgeInsets.only(
left: 20, right: 125, top: 5),
child: RichText(
text: TextSpan(children: <TextSpan>[
TextSpan(
text: "๋‹จ์–ด ์ถ”๊ฐ€์ผ\n",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w400,
color: Colors.black)),
TextSpan(
text:
"${repeat.year}๋…„ ${repeat.month}์›” ${repeat.date}์ผ",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w800,
color: Colors.black))
]))),
Container(
padding: EdgeInsets.only(top: 3),
child: Text("๋‹จ์–ด ๋ณด๊ธฐ",
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w400,
color: Colors.black))),
Container(
padding: EdgeInsets.only(top: 2),
child: IconButton(
icon: Icon(Icons.arrow_forward_ios,
color: Colors.black, size: 15),
onPressed: () => {}))
]),
SizedBox(height: 3),
Row(
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 22, top: 3),
child: Text("๋ณต์Šต์™„๋ฃŒ",
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: Colors.black))),
SizedBox(width: 10),
Container(
padding:
EdgeInsets.only(top: 6, right: 1.5),
decoration: BoxDecoration(
shape: BoxShape.circle,
color:
repeat.repeat.contains('repeat1') ==
true
? Colors.yellow[600]
: Colors.grey[200],
),
width: 30.0,
height: 30.0,
child: Text("1",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Colors.black))),
SizedBox(width: 7),
Container(
padding:
EdgeInsets.only(top: 6, right: 0.5),
decoration: BoxDecoration(
shape: BoxShape.circle,
color:
repeat.repeat.contains('repeat2') ==
true
? Colors.yellow[600]
: Colors.grey[200],
),
width: 30.0,
height: 30.0,
child: Text("2",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Colors.black))),
SizedBox(width: 7),
Container(
padding:
EdgeInsets.only(top: 6, right: 0.5),
decoration: BoxDecoration(
shape: BoxShape.circle,
color:
repeat.repeat.contains('repeat3') ==
true
? Colors.yellow[600]
: Colors.grey[200],
),
width: 30.0,
height: 30.0,
child: Text("3",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Colors.black))),
SizedBox(width: 7),
Container(
padding: EdgeInsets.only(top: 6),
decoration: BoxDecoration(
shape: BoxShape.circle,
color:
repeat.repeat.contains('repeat4') ==
true
? Colors.yellow[600]
: Colors.grey[200],
),
width: 30.0,
height: 30.0,
child: Text("6",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Colors.black))),
SizedBox(width: 7),
Container(
padding: EdgeInsets.only(top: 6),
decoration: BoxDecoration(
shape: BoxShape.circle,
color:
repeat.repeat.contains('repeat5') ==
true
? Colors.yellow[600]
: Colors.grey[200],
),
width: 30.0,
height: 30.0,
child: Text("13",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Colors.black))),
SizedBox(width: 7),
Container(
padding: EdgeInsets.only(top: 6),
decoration: BoxDecoration(
shape: BoxShape.circle,
color:
repeat.repeat.contains('repeat6') ==
true
? Colors.yellow[600]
: Colors.grey[200],
),
width: 30.0,
height: 30.0,
child: Text("28",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Colors.black))),
SizedBox(width: 7),
Container(
padding: EdgeInsets.only(top: 6),
decoration: BoxDecoration(
shape: BoxShape.circle,
color:
repeat.repeat.contains('repeat7') ==
true
? Colors.yellow[600]
: Colors.grey[200],
),
width: 30.0,
height: 30.0,
child: Text("58",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Colors.black))),
],
),
SizedBox(height: 25)
]));
});
}
}));
}
Future<List> loadPrRepeat() async {
DBHelperPrRepeat sd = DBHelperPrRepeat();
List<PrRepeat> list = await sd.repeats();
setState(() {});
list.sort((a, b) => a.createTime.compareTo(b.createTime));
List<PrRepeat> newList = [];
if (list[0].createTime == list[1].createTime) {
newList.add(PrRepeat(
createTime: list[0].createTime,
repeat: list[0].repeat + ', ' + list[1].repeat,
year: list[0].year,
month: list[0].month,
date: list[0].date));
} else {
newList.add(list[0]);
newList.add(list[1]);
}
for (int i = 2; i < list.length; i++) {
if (list[i].createTime == newList.last.createTime) {
PrRepeat last = newList.last;
PrRepeat repeat = PrRepeat(
createTime: last.createTime,
repeat: last.repeat + ', ' + list[i].repeat,
year: last.year,
month: last.month,
date: last.date);
newList.removeLast();
newList.add(repeat);
} else {
newList.add(list[i]);
}
}
return newList;
}
}
You have to check for the length of this list List<PrRepeat> list = await sd.repeats();:
...
if(list.length == 0){
return newList;
} else if(list.length == 1){
newList.addAll(list);
return newList;
}
if (list[0].createTime == list[1].createTime) {
newList.add(PrRepeat(
createTime: list[0].createTime,
repeat: list[0].repeat + ', ' + list[1].repeat,
year: list[0].year,
month: list[0].month,
date: list[0].date));
} else {
newList.add(list[0]);
newList.add(list[1]);
}
if(list.length < 3){
return newList;
}
...