By updating Flutter 3.8.0 Error in flutter_date_time_picker

5.4k Views Asked by At

By updating Flutter 3.8.0 I am getting the following error in flutter_date_time_picker. I would like to know if anyone knows a solution to this problem.

../../../../.pub-cache/git/flutter_datetime_picker-eb66486c47d50bf550950c196486121ffcea8885/lib/flutter_datetime_picker.dart:7: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'.

pubspeck.yaml

  flutter_datetime_picker:
    git:
      url: https://github.com/Realank/flutter_datetime_picker.git

If anyone knows of a solution, I would love to hear about it.

I believe this is probably due to the flutter update, as I was able to build normally until yesterday! If anyone knows of a solution, I would love to hear about it.

7

There are 7 best solutions below

0
On

first try to flutter clean and then pub get and reinstall the package you want. if again you had this error try this: To resolve it; in the class where you have both imports, assign an alias to one of the packages using the as keyword.

import 'package:flutter/src/material/date_picker_theme.dart' as dp
dp.EveryMethodYouWant(); //call the class using the alias

if you had any question i'm here.

happy coding.

0
On

By mistakenly,you have imported the wrong package because as per the package documentation, there is no such line mentioned.

Import the package mentioned below and try pub get.

import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';

everything vill works fine.

1
On

you may use

https://pub.dev/packages/flutter_datetime_picker_plus

It is a Forked from (Pub) flutter_datetime_picker as it had issues with dart 3.0

1
On

I had the same issue caused by Material and flutter_datetime_picker sharing names. It can be solved by adding an alias to your import then specifying which plugin is being used:

import 'package:flutter/material.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart' as PluginDatetimePicker;

Then when calling your objects in your code you must specify that it is coming from PluginDatetimePicker:

PluginDatetimePicker.DatePicker.showDatePicker(
     context,
     locale: PluginDatetimePicker.LocaleType.en,
     theme: PluginDatetimePicker.DatePickerTheme(
            headerColor: headerColorX,
            backgroundColor: backgroundColorX,
            itemStyle: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 22),
            doneStyle: TextStyle(color: Colors.white, fontSize: 16),
     ), 
     onConfirm: (date) {
         // onConfirm()
     });
1
On

you can also use this package "flutter_datetime_picker_plus"

[https://pub.dev/packages/flutter_datetime_picker_plus/install][1]

it works exactly like flutter_datetimer_picker you just have to install and that's all.

0
On

Name Clash

This error:

'DatePickerTheme' is imported from both

is telling us two classes imported into the current file from different packages have the same name.

Dart cannot tell which to use, hence the error.

Two common solutions

  1. hide (don't import) one of the classes
  2. Apply a prefix to one of the packages

Hide

Here's an example of hiding a single class from being imported from a package:

import 'package:text_widgets/text_widgets.dart' hide TextThemeExt;

Above the class named TextThemeExt won't be imported and won't clash with an identically named class in the current file.

Prefix

import 'dart:math' as math;

This is a very common prefix applied to the math library in dart. (So people reading the code understand these are symbols from the math library and not some short variable name in the current file.)

Any symbol within the math library now must be prefixed with math to be used.

For example:

Matrix4.rotationX(math.pi)

Without the prefix in the import statement the above would be:

Matrix4.rotationX(pi)

Summary

In this particular case, the author of the package chose a name for a class they created that conflicts with the name of a class in the Flutter Material package, which is a pretty essential package for most Flutter devs.

In the proposed fix, a person offered to hide Flutter's DatePickerTheme class from being imported.

If you're using this package from this author, there's not much for you to do besides wait for them to merge the change and publish a new version of their package.

0
On

using an alias on importing package works for me. I'm using material an flutter_datetime_picker in same dart file.