From 0d9eb0a9536c414dc2941f0556ad90b411d40cd1 Mon Sep 17 00:00:00 2001 From: sivaprasadnk Date: Fri, 19 Jul 2024 20:51:40 +0530 Subject: [PATCH] adding textStyle for month texts --- example/android/app/build.gradle | 2 +- example/ios/Flutter/flutter_export_environment.sh | 4 ++-- example/lib/main.dart | 4 ++++ lib/src/helpers/controller.dart | 2 ++ lib/src/month_selector/month_button.dart | 6 ++++++ lib/src/month_selector/month_year_grid.dart | 2 ++ lib/src/show_month_picker.dart | 2 ++ lib/src/show_month_range_picker.dart | 4 ++++ lib/src/year_selector/year_button.dart | 1 + test/month_picker_dialog_test.dart | 8 ++++++++ 10 files changed, 32 insertions(+), 3 deletions(-) diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index b5399f9..7090ea6 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -39,7 +39,7 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "edu.hm.krivoj.monthpickerdialogexample" - minSdkVersion 20 + minSdkVersion flutter.minSdkVersion targetSdkVersion 30 versionCode flutterVersionCode.toInteger() versionName flutterVersionName diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh index 722f3c3..4b00e3f 100755 --- a/example/ios/Flutter/flutter_export_environment.sh +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -1,7 +1,7 @@ #!/bin/sh # This is a generated file; do not edit or check into version control. -export "FLUTTER_ROOT=C:\flutter" -export "FLUTTER_APPLICATION_PATH=C:\Users\gian_\Desktop\month_picker_dialog\example" +export "FLUTTER_ROOT=C:\Users\HP\Downloads\flutter\flutter" +export "FLUTTER_APPLICATION_PATH=D:\SP\flutterProj\sample_projs\forked_repos\month_picker_dialog\example" export "COCOAPODS_PARALLEL_CODE_SIGN=true" export "FLUTTER_TARGET=lib\main.dart" export "FLUTTER_BUILD_DIR=build" diff --git a/example/lib/main.dart b/example/lib/main.dart index 862e0af..7cd0626 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -156,6 +156,10 @@ class _MyAppState extends State { }); */ showMonthRangePicker( context: context, + textStyle: TextStyle( + color: Colors.black, + fontWeight: FontWeight.bold, + ), firstDate: DateTime(DateTime.now().year - 5, 5), lastDate: DateTime(DateTime.now().year + 8, 9), initialDate: selectedDate ?? widget.initialDate, diff --git a/lib/src/helpers/controller.dart b/lib/src/helpers/controller.dart index 553a753..76ced8e 100644 --- a/lib/src/helpers/controller.dart +++ b/lib/src/helpers/controller.dart @@ -43,9 +43,11 @@ class MonthpickerController { required this.headerTitle, required this.rangeMode, required this.rangeList, + required this.textSyle, }); //User defined variables + final TextStyle? textSyle; final ThemeData theme; final DateTime? firstDate, lastDate, initialDate; final Locale? locale; diff --git a/lib/src/month_selector/month_button.dart b/lib/src/month_selector/month_button.dart index bc05847..923ff03 100644 --- a/lib/src/month_selector/month_button.dart +++ b/lib/src/month_selector/month_button.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; + import '/month_picker_dialog.dart'; ///The button to be used on the grid of months. @@ -88,6 +89,11 @@ class MonthButton extends StatelessWidget { } return TextButton.styleFrom( + textStyle: controller.textSyle ?? + theme.textTheme.labelLarge ?? + TextStyle( + fontWeight: FontWeight.bold, + ), foregroundColor: foregroundColor, backgroundColor: backgroundColor, shape: controller.buttonBorder, diff --git a/lib/src/month_selector/month_year_grid.dart b/lib/src/month_selector/month_year_grid.dart index a66eff6..4a25c5d 100644 --- a/lib/src/month_selector/month_year_grid.dart +++ b/lib/src/month_selector/month_year_grid.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; + import '/month_picker_dialog.dart'; ///The month grid. It has all of the avaliable options to be selected. @@ -25,6 +26,7 @@ class MonthYearGridBuilder extends StatelessWidget { 12, (final int index) => MonthButton( theme: controller.theme, + date: DateTime( controller.localFirstDate != null ? controller.localFirstDate!.year + page diff --git a/lib/src/show_month_picker.dart b/lib/src/show_month_picker.dart index de76886..1f9b04e 100644 --- a/lib/src/show_month_picker.dart +++ b/lib/src/show_month_picker.dart @@ -71,6 +71,7 @@ import '/month_picker_dialog.dart'; /// Future showMonthPicker({ required BuildContext context, + TextStyle? textStyle, DateTime? initialDate, DateTime? firstDate, DateTime? lastDate, @@ -110,6 +111,7 @@ Future showMonthPicker({ 'forceSelectedDate can only be used with dismissible = true'); final ThemeData theme = Theme.of(context); final MonthpickerController controller = MonthpickerController( + textSyle: textStyle, initialDate: initialDate, firstDate: firstDate, lastDate: lastDate, diff --git a/lib/src/show_month_range_picker.dart b/lib/src/show_month_range_picker.dart index e875b9d..adaee23 100644 --- a/lib/src/show_month_range_picker.dart +++ b/lib/src/show_month_range_picker.dart @@ -15,6 +15,8 @@ import '/month_picker_dialog.dart'; /// /// `monthStylePredicate:` allows you to individually customize each month. /// +/// `textStyle:` allows you to customize text-style of month. +/// /// `yearStylePredicate:` allows you to individually customize each year. /// /// `capitalizeFirstLetter:` lets you control if your months names are capitalized or not. @@ -73,6 +75,7 @@ import '/month_picker_dialog.dart'; /// Future?> showMonthRangePicker({ required BuildContext context, + TextStyle? textStyle, DateTime? initialDate, DateTime? firstDate, DateTime? lastDate, @@ -113,6 +116,7 @@ Future?> showMonthRangePicker({ 'forceSelectedDate can only be used with dismissible = true'); final ThemeData theme = Theme.of(context); final MonthpickerController controller = MonthpickerController( + textSyle: textStyle, initialDate: initialDate, firstDate: firstDate, lastDate: lastDate, diff --git a/lib/src/year_selector/year_button.dart b/lib/src/year_selector/year_button.dart index bba0614..e7dcd0f 100644 --- a/lib/src/year_selector/year_button.dart +++ b/lib/src/year_selector/year_button.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; + import '/month_picker_dialog.dart'; ///The button to be used on the grid of years. diff --git a/test/month_picker_dialog_test.dart b/test/month_picker_dialog_test.dart index 9601b1d..b80bc9b 100644 --- a/test/month_picker_dialog_test.dart +++ b/test/month_picker_dialog_test.dart @@ -5,6 +5,10 @@ import 'package:month_picker_dialog/src/helpers/controller.dart'; void main() { test('default_controller_test', () { final MonthpickerController controller = MonthpickerController( + textSyle: ThemeData.fallback().textTheme.labelLarge ?? + TextStyle( + fontWeight: FontWeight.bold, + ), capitalizeFirstLetter: false, yearFirst: true, roundedCornersRadius: 0, @@ -39,6 +43,10 @@ void main() { test('controller_with_parameters_test', () { final MonthpickerController controller = MonthpickerController( + textSyle: ThemeData.fallback().textTheme.labelLarge ?? + TextStyle( + fontWeight: FontWeight.bold, + ), capitalizeFirstLetter: false, yearFirst: true, roundedCornersRadius: 0,