1
/C:/Users/shivam%20bunkar/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_datetime_picker-1.5.1/lib/flutter_datetime_picker.dart:6:1: Error: 'DatePickerTheme' is imported from both 'package:flutter/src/material/date_picker_theme.dart' and 'package:flutter_datetime_picker/src/datetime_picker_theme.dart'.
import 'package:flutter/material.dart';
^^^^^^^^^^^^^^^
/C:/Users/shivam%20bunkar/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_datetime_picker-1.5.1/lib/flutter_datetime_picker.dart:200:31: Error: 'DatePickerTheme' is imported from both 'package:flutter/src/material/date_picker_theme.dart' and 'package:flutter_datetime_picker/src/datetime_picker_theme.dart'.
        this.theme = theme ?? DatePickerTheme(),
                              ^^^^^^^^^^^^^^^      

How do I solve this problem? Flutter SDK version: 3.3.10

flexagoon
  • 170
  • 8

3 Answers3

0

I faced the same error when I upgraded Flutter to v3.10.5.

The thing that you need to know is from where you are getting the function showTimePicker()

Before I was using this package flutter_datetime_picker to access the function with the below code.

/// Before
DatePicker.showTimePicker(context,
    showTitleActions: true,
    onChanged: (date) {},
    onConfirm: (date) {
    String hour = date.hour.toString();
    String minute = date.minute.toString();
    String second = date.second.toString();
});

After upgrading Flutter SDK, the error occurred since Flutter SDK itself provides this function. So, you need to do the following:

  1. remove external package (flutter_datetime_picker) from pubspec.yaml.
  2. upgrade your sdk in pubspec.yaml to ">=3.0.0 <4.0.0" to access Flutter new functionalities. (my assumption your flutter sdk is already upgraded).
  3. flutter clean
  4. flutter pub get
  5. use below code and ensure showTimePicker is taken from [packages/flutter/lib/src/material/time_picker.dart]
/// After
Future<TimeOfDay?> sd = showTimePicker(
    context: context,
    initialTime: TimeOfDay.now(),
);
/// get [Time] object using then
sd.then((date) {
    String? hour = date?.hour.toString();
    String? hour = date?.minute.toString();
}

Please note that my code is to return only [Time], since this is what I want. If you need to access [Date] you can use showDatePicker function.

Bassam A.
  • 141
  • 1
  • 6
0
  1. use this package--->>>flutter_datetime_picker_plus: ^2.0.1 2.import 'package:flutter_datetime_picker_plus/flutter_datetime_picker_plus.dart' as picker;
  2. picker.method()

it is working with the latest version... Thank u

-1

The error you are getting is caused by a conflict between the DatePickerTheme class in the flutter_datetime_picker package and the DatePickerTheme class in the flutter/src/material/date_picker_theme.dart file.

To fix this, you can either:

  1. Remove the flutter_datetime_picker package from your project.
  • You shouldn't rename classes in third-party packages. If you want to import the package along with `material.dart` you can add `hide DatePickerTheme` after the material import. – flexagoon May 26 '23 at 08:30