M-amir-M / persian-datetime-picker

a persian (farsi) date time picker in flutter
BSD 3-Clause "New" or "Revised" License
179 stars 97 forks source link

One of the error texts overflow in input entry mode of the Date Range Picker #69

Open amirkazemzade opened 10 months ago

amirkazemzade commented 10 months ago

Issue:

Error text overflow when inputting not in range value in input entry mode of the Date Range Picker causes the error text not to be readable.

Screenshot:

image

Reproducing Example Code:

import 'package:flutter/material.dart';
import 'package:persian_datetime_picker/persian_datetime_picker.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(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Row(
        children: [
          // Default Flutter Date Range Picker
          Expanded(
            child: Center(
              child: FilledButton(
                child: const Text('select date range'),
                onPressed: () {
                  showDateRangePicker(
                    context: context,
                    firstDate: DateTime(2020),
                    lastDate: DateTime(2024),
                    initialDateRange: DateTimeRange(
                      start: DateTime.now(),
                      end: DateTime.now(),
                    ),
                    initialEntryMode: DatePickerEntryMode.input,
                  );
                },
              ),
            ),
          ),
          // Persian Date Range Picker
          Expanded(
            child: Center(
              child: FilledButton(
                child: const Text('انتخاب بازه زمانی'),
                onPressed: () {
                  showPersianDateRangePicker(
                    context: context,
                    initialEntryMode: PDatePickerEntryMode.input,
                    firstDate: Jalali(1400),
                    lastDate: Jalali(1403),
                    initialDateRange: JalaliRange(
                      start: Jalali.now(),
                      end: Jalali.now(),
                    ),
                  );
                },
              ),
            ),
          ),
        ],
      ),
    );
  }
}

Location of The Overflowing Error Text:

In the lib/src/pinput_date_range_picker.dart at lines 174 and 177.

  String? _validateDate(Jalali? date) {
    if (date == null) {
      return widget.errorFormatText ?? 'تاریخ انتخاب شده معتبر نمی باشد.';
    } else if (date.isBefore(widget.firstDate) ||
        date.isAfter(widget.lastDate)) {
      return widget.errorInvalidText ?? 'تاریخ انتخاب شده معتبر نمی باشد.';
    }
    return null;
  }

Suggested Solution:

Using shorter error text such as other error texts in this widget such as تاریخ معتبر نمی باشد. or direct translation of default flutter range picker error message in this situation (Out of range.). My suggested translation is .خارج از محدوده.

amirkazemzade commented 10 months ago

I just created a pull request fixing the issue using the suggested solution and the تاریخ معتبر نمی باشد. error text. Pull Request: https://github.com/M-amir-M/persian-datetime-picker/pull/70