skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
  4. using an alias on importing package works for me. I’m using material an flutter_datetime_picker in same dart file.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search