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.
4
Answers
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.
if you had any question i’m here.
happy coding.
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.
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
hide
(don’t import) one of the classesHide
Here’s an example of hiding a single class from being imported from a package:
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 themath
library and not some short variable name in the current file.)Any symbol within the
math
library now must be prefixed withmath
to be used.For example:
Without the prefix in the import statement the above would be:
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’sDatePickerTheme
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.
using an alias on importing package works for me. I’m using material an flutter_datetime_picker in same dart file.