GaspardMerten / date_field

Flutter DateField and DateFormField
Other
45 stars 32 forks source link

Change calendar and timer default color #25

Closed gdet closed 2 years ago

gdet commented 2 years ago

Hello! Is it possible when you press the field and the calendar pops up to change the default color of the calendar? Currently it is blue. The same goes for time selection. Thank you

GaspardMerten commented 2 years ago

Hello,

For that, you should use the Theme widget of the Material widgets library.

https://www.raywenderlich.com/16628777-theming-a-flutter-app-getting-started

Could you confirm that you could resolve your issue using that approach?

Allowing you to customize the colour using the widgets in my package would be against the way Flutter theming works...

Wizely99 commented 1 year ago

THIS IS HOW I'VE DONE IT


              data: Theme.of(context).copyWith(
                colorScheme: const ColorScheme.light(
                  primary: Colors.black12,
                  onPrimary: primaryColor, // <-- SEE HERE
                  //onSurface: Colors.black, // <-- SEE HERE
                ),
                textButtonTheme: TextButtonThemeData(
                  style: TextButton.styleFrom(
                    foregroundColor: Colors.red, // button text color
                  ),
                ),
              ),
              child: DateTimeFormField(
                mode: DateTimeFieldPickerMode.date,
                decoration: const InputDecoration(
                  hintStyle: TextStyle(color: Colors.black45),
                  errorStyle: TextStyle(color: Colors.redAccent),
                  border: OutlineInputBorder(),
                  prefixIcon: Icon(Icons.event_note),
                  labelText: 'Due date',
                  prefixIconColor: primaryColor,
                ),
                firstDate: DateTime.now(),
                lastDate: DateTime.now().add(
                  const Duration(days: 700),
                ),
                initialDate: _selectedDate,
                autovalidateMode: AutovalidateMode.always,
                validator: (DateTime? e) =>
                    (e?.day ?? 0) == 1 ? 'Please not the first day' : null,
                onDateSelected: (DateTime value) {
                  setState(() {
                    _selectedDate = value;
                  });
                },
              ),
            ),```
_Hope it helps someone out there_