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;
});
},
),
),
),
Related
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’m wondering if there is a possibility to change the hover radius of buttons inside a Date Picker component? The default radius looks too big. Thanks in advance!
Our current code only changes colors, but not the radius of the hover.
return Theme(
data: Theme.of(context).copyWith(
colorScheme: ColorScheme.light(
primary: accentColor, // header background color
onSecondary: colorSecondary,
onPrimary: colorBlack, // header text color
onSurface: colorBlack, // body text color
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
primary: colorBlack, // button text color
),
),
),
child: Center(
child:
ConstrainedBox(
constraints: BoxConstraints(
maxWidth: Responsive.isMobile(context) ? MediaQuery.of(context).size.width : 500.0,
maxHeight: Responsive.isMobile(context) ? MediaQuery.of(context).size.height : 490,
),
child: child,
)
));
try using Theme Widget for date picker
showDatePicker(
builder: (context,child){
return Theme(
data: Theme.of(context).copyWith(
colorScheme: ColorScheme.light(
primary: Colors.black, // header background color
onPrimary: Colors.white, // header text color
onSurface: Colors.black, // body text color
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
primary: Colors.black, // button text color
),
),
),
child: child!,
);
},
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(2022),
lastDate: DateTime(2025),
)
In my Flutter app the user can define a custom Theme by picking the colors from color pickers. After that they can save the ThemeData to a list and use it. The problem is that after the app restarts the ThemeData added by the user disappers. How can I store these ThemeData-s into the list to remain even after the app restarts?
Here is my code:
The ThemeData list:
I also have two ThemeData which is added by default.
List<ThemeData> toReturnTheme = <ThemeData>[];
List<ThemeData> getThemes() {
ThemeData szikraTheme = ThemeData(
scaffoldBackgroundColor: Color(0xff5a89ba),
backgroundColor: Color(0xff5a89b0),
buttonColor: Color(0xfff78848),
accentColor: Colors.white,
floatingActionButtonTheme: FloatingActionButtonThemeData(
backgroundColor: Color(0xff3a89ba),
),
textTheme: TextTheme(
bodyText2: TextStyle(color: Colors.white, fontFamily: 'Muli')));
ThemeData cobotTheme = ThemeData(
scaffoldBackgroundColor: Color(0xff207ABB),
backgroundColor: Color(0xff207ABB),
buttonColor: Color(0xfff78848),
accentColor: Colors.white,
floatingActionButtonTheme: FloatingActionButtonThemeData(
backgroundColor: Color(0xff3a89ba),
),
textTheme: TextTheme(
bodyText2: TextStyle(color: Colors.white, fontFamily: 'Muli')));
toReturnTheme.add(szikraTheme);
toReturnTheme.add(cobotTheme);
return toReturnTheme;
}
void addToThemeList(ThemeData theme){
toReturnTheme.add(theme);
}
The Button that adds the new ThemeData to the list:
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
style: TextButton.styleFrom(
side: BorderSide(
color: Theme.of(context).accentColor,
)),
onPressed: () {
try {
ThemeData customTheme = ThemeData(
scaffoldBackgroundColor:
Color(bckgrndColor!.value),
backgroundColor: Color(bckgrndColor!.value),
buttonColor: Color(buttonColor!.value),
accentColor: Color(fontColor!.value),
floatingActionButtonTheme:
FloatingActionButtonThemeData(
backgroundColor: Color(arrowColor!.value),
),
textTheme: TextTheme(
bodyText2: TextStyle(
color: Color(fontColor!.value),
fontFamily: 'Muli'),
bodyText1: TextStyle(
color: Color(fontColor!.value),
fontFamily:
customThemeController.text)));
customThemeController.clear();
addToThemeList(customTheme);
saveTheme();
final snackBar = SnackBar(
behavior: SnackBarBehavior.floating,
content: Text(
"themeCreated".tr().toString(),
));
ScaffoldMessenger.of(context)
.showSnackBar(snackBar);
} catch (e) {
final snackBar = SnackBar(
behavior: SnackBarBehavior.floating,
backgroundColor: Colors.redAccent,
content: Text(
"chooseValidColors".tr().toString(),
));
ScaffoldMessenger.of(context)
.showSnackBar(snackBar);
}
setState(() {});
},
child: Text(
"createNewTheme".tr().toString(),
style: TextStyle(
color: Theme.of(context).accentColor,
fontSize: 25.0,
),
)),
),
And the ListView that displays the list of ThemeData:
Container(
width: MediaQuery.of(context).size.width / 2,
height: 100,
child: ListView.builder(
shrinkWrap: true,
itemCount: toReturnTheme.length,
itemBuilder: (context, int index) {
if (index < 2) {
return Container();
} else {
return Container(
child: Column(
children: [
ListTile(
title: GestureDetector(
child: Text(
toReturnTheme[index]
.textTheme
.bodyText1!
.fontFamily
.toString() ==
""
? "Custom Theme"
: toReturnTheme[index]
.textTheme
.bodyText1!
.fontFamily
.toString(),
style: TextStyle(
fontSize: 22.0,
color: Theme.of(context)
.accentColor),
),
onTap: () {
getThemeManager(context)
.selectThemeAtIndex(index);
},
),
trailing: GestureDetector(
child: Icon(
Icons.delete,
color: Theme.of(context).accentColor,
),
onTap: () {
toReturnTheme.removeAt(index);
setState(() {});
},
),
leading: Icon(
Icons.palette_outlined,
color: Theme.of(context).accentColor,
),
),
],
),
);
}
}),
),
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));
},
),
),
xylophone pic
The last thing I would like to change on this app is the color of the text to make it blend better with the background color of each bar.
For example, I would like to change the 'Red' text to yellow. I would like to change the 'Light blue' text to orange.
import 'package:audioplayers/audio_cache.dart';
import 'package:flutter/material.dart';
void main() => runApp(XylophoneApp());
class XylophoneApp extends StatelessWidget {
void buttonSound(int noteNumber) {
final player = AudioCache();
player.play('note$noteNumber.wav');
}
Expanded buildKey(
{Color color, int noteNumber, String text}) {
return Expanded(
child: FlatButton(
color: color,
onPressed: () {
buttonSound(noteNumber);
},
child: Center(
child: Text(
text,
style: TextStyle(
fontFamily: 'Vast Shadow',
fontSize: 20,
color: Colors.black.withOpacity(0.5),
fontWeight: FontWeight.w700,
letterSpacing: 2,
),
),
),
),
);
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.black,
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
buildKey(color: Colors.red, noteNumber: 1, text: 'Red'),
buildKey(color: Colors.blue, noteNumber: 2, text: 'Light Blue'),
buildKey(color: Colors.orangeAccent, noteNumber: 3, text: 'Orange Accent'),
buildKey(color: Colors.deepPurpleAccent, noteNumber: 4, text: 'Purple'),
buildKey(color: Colors.lightGreen, noteNumber: 5, text: 'Key Lime'),
buildKey(color: Colors.blueGrey, noteNumber: 6, text: 'Blue Grey'),
buildKey(color: Colors.lime, noteNumber: 7, text: 'Yellow Accent'),
],
),
),
),
);
}
}
Add another parameter for the text color
{Color color, int noteNumber, String text, Color textColor}) {
return Expanded(
child: FlatButton(
color: color,
onPressed: () {
buttonSound(noteNumber);
},
child: Center(
child: Text(
text,
style: TextStyle(
fontFamily: 'Vast Shadow',
fontSize: 20,
color: textColor,
fontWeight: FontWeight.w700,
letterSpacing: 2,
),
),
),
),
);
}
Then call the method passing the text color
buildKey(color: Colors.red, noteNumber: 1, text: 'Red', textColor: Colors.yellow)
Make sure you pass the textColor.