How to change the title and other text's font family, size etc????
Asked
Active
Viewed 1,707 times
2
lepsch
- 8,927
- 5
- 24
- 44
Ananta Dev Datta
- 53
- 7
-
this allows you a complete customization, https://stackoverflow.com/questions/50321182/how-to-customize-a-date-picker – jmvcollaborator Sep 10 '22 at 09:37
2 Answers
5
Use the Theme widget to customize the fonts, size and color and many other properties of showDatePicker. Just add the property builder to showDatePicker and wrap the child with the Theme widget.
Take a look at the live demo on DartPad
Here's the source:
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
debugShowCheckedModeBanner: false,
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
void _showDatePicker() {
// showMaterialDatePicker(context: context);
showDatePicker(
context: context,
initialDate: DateTime(2022),
firstDate: DateTime(2022),
lastDate: DateTime(2023),
// initialDatePickerMode: DatePickerMode.year,
initialEntryMode: DatePickerEntryMode.calendar,
builder: (context, child) {
return Theme(
data: Theme.of(context).copyWith(
dialogBackgroundColor: Colors.yellow, // days/years gridview
textTheme: TextTheme(
headline5: GoogleFonts.greatVibes(), // Selected Date landscape
headline6: GoogleFonts.greatVibes(), // Selected Date portrait
overline: GoogleFonts.greatVibes(), // Title - SELECT DATE
bodyText1: GoogleFonts.greatVibes(), // year gridbview picker
subtitle1: GoogleFonts.greatVibes(color: Colors.black), // input
subtitle2: GoogleFonts.greatVibes(), // month/year picker
caption: GoogleFonts.greatVibes(), // days
),
colorScheme: Theme.of(context).colorScheme.copyWith(
// Title, selected date and day selection background (dark and light mode)
surface: Colors.amber,
primary: Colors.amber,
// Title, selected date and month/year picker color (dark and light mode)
onSurface: Colors.black,
onPrimary: Colors.black,
),
// Buttons
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
foregroundColor: Colors.yellow,
backgroundColor: Colors.pink,
textStyle: GoogleFonts.greatVibes(),
),
),
// Input
inputDecorationTheme: InputDecorationTheme(
labelStyle: GoogleFonts.greatVibes(), // Input label
),
),
child: child!,
);
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: _showDatePicker,
tooltip: 'Increment',
child: const Icon(Icons.calendar_month),
),
);
}
}
lepsch
- 8,927
- 5
- 24
- 44
0
You can specify fonts in ThemeData() in main.dart.
ThemeData(fontFamily: //Define your font)
NOTE:- It will affects in whole app.
Harsh Sureja
- 1,052
- 1
- 9
- 22




