1

Want to change the TextStyle of helpText in showDateRangePicker() in Flutter.

Can anybody Help.

This the UI right now.

Want to Increase the size of this & color too


  buildMaterialDatePicker({BuildContext context, SearchVM model}) 
   async {
    final DateTimeRange picked = await showDateRangePicker(
      context: context,
      firstDate: initialDate,
      helpText: 'Select a Date or Date-Range',
      fieldStartHintText: 'Start Booking date',
      fieldEndHintText: 'End Booking date',
      currentDate: initialDate,
      lastDate: DateTime(2020, initialDate.month + 1, 
      initialDate.day),
      builder: (BuildContext context, Widget child) {
        return Theme(
          data: ThemeData.dark().copyWith(
            colorScheme: ColorScheme.dark(
              primary: Colors.greenAccent,
              onPrimary: oppColor,
              surface: Colors.greenAccent,
              onSurface: oppColor,
            ),
            dialogBackgroundColor: mainColor,
          ),
          child: child,
        );
      },
    );
  }
void
  • 12,787
  • 3
  • 28
  • 42
DIVYANSHU SAHU
  • 1,035
  • 11
  • 24

2 Answers2

3

So, according to the answer of abbas jafary answer. I deep Dived into the Documentation of the showDateRangePicker() (you can do so using Ctrl+ Right-Clicking) and found what texstTheme it is using for that Text.

 Text(
       helpText,
       style: textTheme.overline.apply(
       color: headerForeground,),
 ),

So, Then I wrapped my Widget with Theme and updated the textTheme field.

buildMaterialDatePicker({BuildContext context, SearchVM model}) async {
    final DateTimeRange picked = await showDateRangePicker(
      context: context,
      firstDate: initialDate,
      helpText: 'Select a Date or Date-Range',
      fieldStartHintText: 'Start Booking date',
      fieldEndHintText: 'End Booking date',
      currentDate: initialDate,
      lastDate: DateTime(2020, initialDate.month + 1, initialDate.day),
      builder: (BuildContext context, Widget child) {
        return Theme(
          data: ThemeData.dark().copyWith(
            colorScheme: ColorScheme.dark(
              primary: Colors.greenAccent,
              onPrimary: oppColor,
              surface: Colors.greenAccent,
              onSurface: oppColor,
            ),

          // Here I Chaged the overline to my Custom TextStyle.
            textTheme: TextTheme(overline: TextStyle(fontSize: 16)),
            dialogBackgroundColor: mainColor,
          ),
          child: child,
        );
      },
    );
   
}

Here is the Output of what I get

DIVYANSHU SAHU
  • 1,035
  • 11
  • 24
0

For change colors, font and etc. You must wrap element into Theme:

Widget returnRangePicker(BuildContext context) {
    return Theme(
      data: Theme.of(context).copyWith(
          accentColor: Colors.green,
          primaryColor: Colors.blue,
          buttonTheme: ButtonThemeData(
              highlightColor: Colors.green,
              buttonColor: Colors.green,
              colorScheme: Theme.of(context).colorScheme.copyWith(
                  secondary: epapGreen,
                  background: Colors.white,
                  primary: Colors.green,
                  primaryVariant: Colors.green,
                  brightness: Brightness.dark,
                  onBackground: Colors.green),
              textTheme: ButtonTextTheme.accent)),
      child: Builder(
        builder: (context) => FlatButton(
          onPressed: () async {
            final List<DateTime> picked = await DateRangePicker.showDatePicker(
                context: context,
                initialFirstDate: DateTime.now(),
                initialLastDate:
                    DateTime.now()).add(Duration(days: 7),
                firstDate: DateTime(2015),
                lastDate: DateTime(2020));
            if (picked != null && picked.length == 2) {
              print(picked);
            }
          },
          child: Text(
            "Choose range",
            style: TextStyle(color: Colors.green),
          ),
        ),
      ),
    );
  }

For more info you can check out the docs. or check this link

Abbas Jafari
  • 1,492
  • 2
  • 16
  • 28