Reputation: 1
Actually i am working on a github project which i downloaded it and practicing on it, but i am stuck in selecting the dates i used for loop to list the dates but when ever i click on it it isn't selecting those dates only the first date is selected already but other dates isn't selecting.
Leme show u the output: here is the dates which i am trying to select but nothing happens also with the categories of learners and with the times too if u can help me with the dates i can understand the problem and fix the others too. Thank you!
Also forgive me for my bad english grammar.
here is the body part:
body: Column(
children: [
Row(
children: [
Container(
width: 200,
height: 260,
child: Stack(
children: [
Positioned(
left: 0,
top: 0,
child: Container(
width: 200,
height: 240,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('asset/images/iconBg.png'),
fit: BoxFit.contain)),
),
),
Positioned(
bottom: 0,
left: 20,
child: Hero(
tag: "boy2",
child: Container(
height: 220,
width: 200,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('asset/images/boy2.png'))),
),
),
)
],
),
),
Expanded(
child: Container(
padding: EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Mr. Muneeb",
style: TextStyle(
fontSize: 21,
fontWeight: FontWeight.w700,
fontFamily: 'product'),
),
SizedBox(
height: 5,
),
Text(
"React Native",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
color: darkBlue,
fontFamily: 'circe'),
),
SizedBox(
height: 15,
),
Row(
children: [
Container(
height: 20,
width: 20,
child: RotatedBox(
quarterTurns: 2,
child: Icon(
Icons.star,
color: darkBlue,
),
),
),
SizedBox(
width: 5,
),
Text(
"4.9 Star Rating",
style: TextStyle(fontFamily: 'circe'),
)
],
),
SizedBox(
height: 10,
),
Row(
children: [
Container(
height: 20,
width: 20,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'asset/images/palette.png'))),
),
SizedBox(
width: 5,
),
Text(
"5 Years Experience",
style: TextStyle(fontFamily: 'circe'),
)
],
),
],
),
),
)
],
),
Expanded(
child: Container(
width: MediaQuery.of(context).size.width,
padding: EdgeInsets.all(30),
color: Colors.white,
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"About Muneeb",
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 17,
fontFamily: 'product'),
),
SizedBox(
height: 10,
),
Text(
"I have been working on a React Native in a industry for almost 5 years working as a front-end developer, I can insure that i can teach you the best methods of working on a react native.",
style: TextStyle(
fontFamily: 'circe',
fontSize: 12,
),
),
SizedBox(
height: 20,
),
Text(
"Courses by Muneeb",
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 17,
fontFamily: 'product'),
),
SizedBox(
height: 10,
),
Container(
height: 100,
width: MediaQuery.of(context).size.width,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
courseWidget("icon1", "Young \nLearners",
"GRADE 0-1", lightBlue, darkBlue),
courseWidget("icon2", "Creative \nBloomers",
"GRADE 0-2", yellow, Color(0xff4d4d4d)),
courseWidget("icon3", "Early \nAchievers",
"GRADE 0-3", pink, Color(0xff4a155f))
],
),
),
),
SizedBox(
height: 20,
),
Text(
"Availability",
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 17,
fontFamily: 'product'),
),
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
for (int i = 0; i < 7; i++) dateWidget(i),
],
),
SizedBox(
height: 10,
),
Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
children: [
timeSlotWidget("11:00 AM", false),
timeSlotWidget("12:00 PM", false),
timeSlotWidget("01:00 PM", false),
timeSlotWidget("03:00 PM", true),
],
),
Row(
children: [
timeSlotWidget("04:00 PM", false),
timeSlotWidget("06:00 PM", false),
],
),
],
),
)
],
),
),
),
),
Here is the datewidget:
InkWell dateWidget(int i) {
DateTime tempDate = DateTime.now().add(Duration(days: i));
return InkWell(
onTap: () {},
child: Container(
margin: EdgeInsets.all(2),
height: 60,
width: MediaQuery.of(context).size.width * 0.11,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(10)),
color: (selectedDate == tempDate.day)
? yellow
: lightBlue.withOpacity(0.5),
),
child: Container(
padding: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
dayValue(tempDate.weekday),
style: TextStyle(fontSize: 10),
),
Text(
tempDate.day.toString(),
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w500),
)
],
),
),
),
);
}
Upvotes: 0
Views: 134
Reputation: 31
Based off of the little information provided;
I suggest using a ListView Builder instead of the row and for loop in the widget tree, it will achieve your goal more effectively.
for example:
//All the available dates for the person
List<DateTime> _dates = <DateTime>[];
//Where to store the selected date
late DateTime _selectedDate;
@override
void initState() {
//set the date
_selectedDate = DateTime.now();
super.initState();
}
ListView.builder(
scrollDirection = Axis.horizontal
primary: false,
shrinkWrap: true,
controller: scrollController,
itemBuilder: (_, index) => dateWidget(_dates[index]),
itemCount: _dates.length),
)
//Date Widget
Widget dateWidget(DateTime date) {
return GestureDetector(
onTap: () {
setState(() {
_selectedDate = date;
});
},
child: Container(
decoration: BoxDecoration(
color: _selectedDate == date ? Colors.yellow : Colors.lightBlueAccent,
),
child: ,
),
);
}
I hope that gives you an idea of how to go about it.
Upvotes: 1