First of all me Make a card like this
Widget MyCard({Color color=Colors.purple,
int date=1,
}){
String _dayName= DateOperartions().getDateNAme(index: date);
return Card(
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50)
),
color: color,
child: Padding(
padding: const EdgeInsets.all(10),
child: Column(
children: [
Text(DateOperartions().getMonthdaysDaysName(), style: TextStyle(
fontSize: 15,
color: Colors.black
),),
Text(date.toString(), style: TextStyle(
fontSize: 15,
color: Colors.black
),),
Text(_dayName.substring(0, 3), style: TextStyle(
fontSize: 15,
color: Colors.black
),),
],
),
),
);
}
Now add card into container
Widget DisplayCard({Color color=Colors.cyanAccent, int date=0, }){
return Container(
width: 100,
child: MyCard(
color: color,
date: date,
)
);
}
Now we need to add dependency or Create a new Model Class
Dpendency
intl: ^0.16.0
Model Class the we use
import 'package:intl/intl.dart';
class DateOperartions{
int _month=DateTime.now().month;
int _year=DateTime.now().year;
String getDateNAme({int index=1}){
var _daynameWeek=DateFormat.EEEE().format(DateTime(_year, _month, index));
return _daynameWeek;
}
int getMonthdays(){
if(_month==1){
return 31;
}
else if(_month==2){
return 28;
}
if(_month==3){
return 31;
}
else if(_month==4){
return 30;
}
if(_month==5){
return 31;
}
else if(_month==6){
return 30;
}
if(_month==7){
return 31;
}
else if(_month==8){
return 31;
}
if(_month==9){
return 30;
}
else if(_month==10){
return 31;
}
if(_month==11){
return 30;
}
else if(_month==12){
return 31;
}
}
String getMonthdaysDaysName(){
if(_month==1){
return "Jan";
}
else if(_month==2){
return "Feb";
}
if(_month==3){
return "Mar";
}
else if(_month==4){
return "Apr";
}
if(_month==5){
return "May";
}
else if(_month==6){
return "Jun";
}
if(_month==7){
return "Jul";
}
else if(_month==8){
return "Aug";
}
if(_month==9){
return "Sep";
}
else if(_month==10){
return "Oct";
}
if(_month==11){
return "Nov";
}
else if(_month==12){
return "Dec";
}
}
int getCurrentDate(){
return DateTime.now().day;
}
}
Now We will create some helping method the we use to display or irritation of loop
List<int> _getList(){
List<int> _datesList=List<int>();
int _currentDate=DateOperartions().getCurrentDate();
int _totalDays=DateOperartions().getMonthdays();
for(int j=_currentDate; j<=_totalDays; j++){
_datesList.add(j);
}
return _datesList;
}
int _getRemaningDAys(){
int _currentDate=DateOperartions().getCurrentDate();
int _totalDays=DateOperartions().getMonthdays();
int _coutner=0;
for(int j=_currentDate; j<=_totalDays; j++){
_coutner++;
}
return _coutner;
}
Now Set or main body to view
class SelectDateTime extends StatefulWidget {
@override
_SelectDateTimeState createState() => _SelectDateTimeState();
}
class _SelectDateTimeState extends State<SelectDateTime> {
int _tabCheck=0;
int _isPress=0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
centerTitle: true,
title: Text("Select date & time", style: TextStyle(
color: Colors.black,
fontSize: 20,
fontWeight: FontWeight.bold
),),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 100,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: _getRemaningDAys(),
itemBuilder: (context, int index){
int _currentDate=DateOperartions().getCurrentDate();
return GestureDetector(
onTap: (){
setState(() {
_tabCheck=index;
});
},
child: index==0?evenCard(
color:_currentDate==_getList()[index] ? Colors.blue : Colors.transparent,
date: _getList()[index],
)
: Container(
width: 100,
child: MyCard(
date: _getList()[index],
color: _tabCheck==index ? Colors.blueGrey : Colors.transparent
),
)
);
},
)
),
); /scaffold
}
}