I'm using the CupertinoDatePicker for setting a date in a form. To match our application design I need the picker to be in dark mode, so I adjusted the backgroundColor. For the text in the picker to be white I wrapped the picker inside a Container with a CupertinoTheme to set the color. I did this based on this solution: How to change font size for CupertinoDatePicker in Flutter?. For some reason this breaks the widths of the columns in the CupertinoDatePicker, and I don't have a clue why that's happening. If I remove the CupertinoTheme the columns are fine but the text is dark too, thus unreadable.
Code:
void showPlatformDatePicker() {
showCupertinoModalPopup(
context: context,
builder: (_) => Container(
color: Colors.black87,
height: 400,
child: Column(
children: [
Container(
color: Color.fromRGBO(18, 18, 18, 1),
alignment: Alignment.centerRight,
child: TextButton(
onPressed: () => Navigator.pop(context),
child: Text(
'Done',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.normal,
color: Colors.white,
),
),
),
),
Container(
height: 350,
width: double.infinity,
child: CupertinoTheme(
data: CupertinoThemeData(
textTheme: CupertinoTextThemeData(
dateTimePickerTextStyle: TextStyle(
color: Colors.white,
),
),
),
child: CupertinoDatePicker(
backgroundColor: Colors.black87,
mode: CupertinoDatePickerMode.date,
maximumDate: DateTime.now().subtract(Duration(days: 365)),
initialDateTime:
DateTime.now().subtract(Duration(days: 365 * 18)),
onDateTimeChanged: (val) {
final date = val.toIso8601String();
context
.bloc<FormBloc>()
.add(DateChanged(date));
},
),
),
),
],
),
),
);
}
Screenshot:
Try using this code
You can edit it according to your requirement
Container(
height: MediaQuery.of(context).size.height * 0.25,
child: CupertinoDatePicker(
initialDateTime: DateTime.now(),
onDateTimeChanged: (DateTime nowDate) {
var currentTime = nowDate;
},
use24hFormat: true,
minimumYear: 2010,
maximumYear: 2018,
minuteInterval: 1,
mode: CupertinoDatePickerMode.dateAndTime,
),
);
Strangely, adding a fontSizeto the CupertinoTextThemeData fixes this issue:
Container(
height: 350,
width: double.infinity,
child: CupertinoTheme(
data: CupertinoThemeData(
textTheme: CupertinoTextThemeData(
dateTimePickerTextStyle: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
),
),
child: CupertinoDatePicker(
backgroundColor: Colors.black87,
mode: CupertinoDatePickerMode.date,
maximumDate: DateTime.now().subtract(Duration(days: 365)),
initialDateTime:
DateTime.now().subtract(Duration(days: 365 * 18)),
onDateTimeChanged: (val) {
final date = val.toIso8601String();
context
.bloc<FormBloc>()
.add(DateChanged(date));
},
),
),
Related
I want to floating action button is front of the alert dialog, I tried add elevation to floatingactionbutton and alertdialog but still not working. is it possible to make floatingactionbutton overlapping all layout including alertdialog?
this my alertdialog using lib rflutter_alert
var alertStyle = AlertStyle(
// animationType: AnimationType.fromTop,
alertElevation: 1,
isCloseButton: false,
isOverlayTapDismiss: false,
descStyle: TextStyle(fontSize: textBody3),
descTextAlign: TextAlign.center,
titleStyle: TextStyle(
color: Colors.red,
fontSize: textHeader1,
fontWeight: FontWeight.bold),
alertAlignment: Alignment.center,
);
Alert(
context: context,
style: alertStyle,
content: Column(
children: <Widget>[
const SizedBox(
height: 30,
),
Text(msg),
const SizedBox(
height: 30,
),
Text(jam)
],
),
buttons: [
DialogButton(
child: Text(
"OK",
style: TextStyle(color: Colors.white, fontSize: textButton1),
),
onPressed: () => Navigator.pop(context),
color: Palette.color_primary,
radius: BorderRadius.circular(0.0),
),
],
image: flag == "OK"
? Image.asset(
"assets/images/success.png",
height: 50,
width: 50,
)
: Image.asset(
"assets/images/error.png",
height: 50,
width: 50,
),
).show();
and this the floatingactionbutton using lib DraggableFab
#override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: DraggableFab(
child: FloatingActionButton.extended(
elevation: 10,
onPressed: () {
getLocation();
},
label:ValueListenableBuilder(
valueListenable: notifierLocFab,
builder: (BuildContext context, bool value,Widget? child) {
return Column(
children: [
Text(latitudeFab.toStringAsFixed(7)),
Text(longitudeFab.toStringAsFixed(7)),
],
);
}),
),
),
);
}
I tried to change the text color of CupertinoDatePicker following this answer and it was successful but when i wanted to change the color of CupertinoTimerPicker it did not change it i want the color of text to be white and the style to be same as the one below
showDialog(
context: context,
builder: (context) {
return AlertDialog(
backgroundColor: const Color(0xff2e2e2e),
title: Column(
children: [
Text(
'Set Duration',
style: TextStyle(
color: Colors.white, fontSize: 16),
),
Divider(
height: 6,
color: Colors.white,
),
],
),
content: CupertinoTheme(
data: CupertinoThemeData(
brightness: Brightness.light,
textTheme: CupertinoTextThemeData(
dateTimePickerTextStyle: TextStyle(color: Colors.red),
),
),
child: CupertinoTimerPicker(
mode: CupertinoTimerPickerMode.hms,
minuteInterval: 1,
secondInterval: 1,
initialTimerDuration: Duration(hours:0, minutes: 0, seconds: 0),
onTimerDurationChanged: (Duration changedTimer) {
setState(() {
initialTimer = changedTimer;
});
},
),
),
);
},
);
I have increased the FontSize and now want to add space between each line. How to that because it doesn't look good.
Couldn't find a way.
Container(
height: 140.h,
width: 335.w,
child: CupertinoTheme(
data: CupertinoThemeData(
textTheme: CupertinoTextThemeData(
dateTimePickerTextStyle: TextStyle(
fontSize: 30.sp,
)),
brightness: Brightness.dark),
child: CupertinoDatePicker(
mode: CupertinoDatePickerMode.time,
initialDateTime: DateTime.now(),
onDateTimeChanged: (val) {
setState(() {
_chosenDateTime = val;
});
},
),
),
),
Here I have a form like this. i want to change the value of the blue button week below when i swipe left or right of Calendar Week. What should i do guys ?. It can only changed when I clicked on the number
Here is the code I'm using:
import 'package:flutter/material.dart';
import 'package:myhumgupdate/App/Config/palette.dart';
import 'package:myhumgupdate/Widgets/dialog_loading.dart';
import 'package:myhumgupdate/giangvien/Screens/XemTKB/TKBTheoTuan/tkbtuan_viewmodel.dart';
import 'package:myhumgupdate/Widgets/calender_week.dart';
import 'package:myhumgupdate/giangvien/models/meeting.dart';
import 'package:myhumgupdate/giangvien/models/meetingdata_source.dart';
import 'package:stacked/stacked.dart';
import 'package:syncfusion_flutter_calendar/calendar.dart';
class TKBTuan extends StatefulWidget {
#override
_TKBTuanState createState() => _TKBTuanState();
}
final String _customTimeLabelText = 'Tiết';
class _TKBTuanState extends State<TKBTuan> {
#override
Widget build(BuildContext context) {
return ViewModelBuilder<TKBTuanViewModel>.reactive(
onModelReady: (model) => Future.delayed(Duration.zero,
() => DialogLoading.show(context, model.getTkbTuan(model.timeNow))),
builder: (context, TKBTuanViewModel model, child) => Column(
children: [
Row(
children: [
Expanded(
child: Container(
margin: EdgeInsets.only(
top: 18,
),
child: CalendarWeek(
calendarController: model.calendarController,
press: (DateTime date, _, __) {
model.getTkbTuan(date);
},
),
),
),
Container(
width: 40,
height: 56,
margin: EdgeInsets.only(right: 3),
padding: EdgeInsets.symmetric(horizontal: 4, vertical: 5),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Palette.kPrimaryColor,
),
child: Center(
child: Text(
"Week ${model.week}",
style: TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
),
),
],
),
Expanded(
child: SfCalendar(
view: CalendarView.week,
firstDayOfWeek: 1,
maxDate: DateTime(DateTime.now().year, DateTime.now().month,
DateTime.now().day, 00, 45, 0),
minDate: DateTime(DateTime.now().year, DateTime.now().month,
DateTime.now().day, 00, 45, 0),
headerHeight: 0,
viewHeaderHeight: 0,
dataSource: MeetingDataSource(model.getDataSource),
appointmentTimeTextFormat: 'hh:mm:ss a',
appointmentBuilder: appointmentBuilder,
initialDisplayDate: DateTime(DateTime.now().year,
DateTime.now().month, DateTime.now().day, 00, 45, 0),
monthViewSettings: MonthViewSettings(showAgenda: true),
timeSlotViewSettings: TimeSlotViewSettings(
startHour: 0,
endHour: 16,
timeFormat: _customTimeLabelText + " H",
timeIntervalHeight: 70,
timeTextStyle: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
)),
// selectionDecoration: BoxDecoration(
// color: Colors.transparent,
// border: Border.all(color: Colors.red, width: 1),
// borderRadius: const BorderRadius.all(Radius.circular(4)),
// shape: BoxShape.rectangle,
// ),
),
),
],
),
viewModelBuilder: () => TKBTuanViewModel());
}
}
Widget appointmentBuilder(BuildContext context,
CalendarAppointmentDetails calendarAppointmentDetails) {
final Meeting appointment = calendarAppointmentDetails.appointments.first;
return Container(
width: calendarAppointmentDetails.bounds.width,
height: calendarAppointmentDetails.bounds.height,
// color: appointment.background,
decoration: BoxDecoration(
color: appointment.background,
border: Border.all(
color: Colors.grey,
width: 0.5,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(2.0, 0, 0, 5.0),
child: Text(
appointment.eventName,
// textAlign: TextAlign.center,
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w500),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(2.0, 0, 0, 0),
child: Text(
"Phòng: ${appointment.subText}",
style: TextStyle(fontSize: 10, fontStyle: FontStyle.italic),
),
)
],
),
);
}
And if there is no way to change the value like that, what should I do and how can I change that?
In the Flutter Event Calendar, you can programmatically select the date using selectedDate property of the CalendarController.
Inside the state, initialize the calendar controller.
final CalendarController _calendarController= CalendarController();
Using onViewChanged callback of the Flutter event calendar, you can set the first date of visible dates as selected date.
child: SfCalendar(
view: CalendarView.month,
controller: _calendarController,
onViewChanged: viewChanged,
),
void viewChanged(ViewChangedDetails viewChangedDetails) {
SchedulerBinding.instance!.addPostFrameCallback((Duration duration) {
_calendarController.selectedDate = viewChangedDetails.visibleDates[0];
});
}
Wrap your Widget in GestureDetector and use onPanUpdate like this:
GestureDetector(onPanUpdate: (details) {
if (details.delta.dx > 0) {
// swiping in right direction
// update week number
}
});
I currently learning Flutter and I'm very new to it. in my app I used responsive grid package and add Text in responsive container. i wanted to go to another page when tap on this text but my bad it gives me this error.
The named parameter 'onTap' isn't defined.
Try correcting the name to an existing named parameter's name, or defining a named parameter with the name 'onTap'.
i used following code:
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Container(
child: ResponsiveGridRow(children: [
ResponsiveGridCol(
lg: 12,
child: Container(
height: 400,
alignment: Alignment.center,
color: Colors.orange,
child: Column(
children: [
Container(
margin: EdgeInsets.only(top: 150),
alignment: Alignment.center,
child: Text("Welcome To",
style: TextStyle(
fontSize: 40,
color: Colors.white)),
),
Container(
alignment: Alignment.center,
child: Text("our App",
style: TextStyle(
fontSize: 40,
color: Colors.white,
fontWeight: FontWeight.bold)),
),
],
),
),
),
ResponsiveGridCol(
xs: 4,
md: 2,
child: Container(
height: 18,
alignment: Alignment.centerLeft,
child: Text("Login",
style: TextStyle(
fontSize: 13,
// decoration: TextDecoration.underline,
color: Colors.orange[800])),
onTap: () { // i got error here
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SignIn()),
);
}
),
)
]),
),
),
);
}
}
Your widget does not have an onTap property you need to create as show below by wrapping the widget that you need to be clickable with a gesture detector or InkWell
GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SignIn()),
);
}
child:Container(
height: 18,
alignment: Alignment.centerLeft,
child: Text("Login",
style: TextStyle(
fontSize: 13,
// decoration: TextDecoration.underline,
color: Colors.orange[800])),
)),
The Container widget does not have onTap property try to wrap it in InkWell like this:
InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SignIn()),
);
},
child: Container(
height: 18,
alignment: Alignment.centerLeft,
child: Text("Login",
style: TextStyle(
fontSize: 13,
// decoration: TextDecoration.underline,
color: Colors.orange[800])),
)))