By updating Flutter 3.8.0 Error in flutter_date_time_picker
Asked Answered
G

7

9

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.

Glissando answered 10/2, 2023 at 4:54 Comment(2)
Remove this import statement. 'package:flutter/src/material/date_picker_theme.dart'Polyhydroxy
Anything update here? What solution is solve to you? I also face that error. Adding prefix cause dependency conflict error.Tubb
A
11

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

Atalaya answered 12/5, 2023 at 5:16 Comment(1)
indeed, worked for meHandout
A
3

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.

Amylolysis answered 9/6, 2023 at 7:2 Comment(1)
B
2

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.

Boron answered 31/3, 2023 at 8:34 Comment(0)
S
2

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

Stomatal answered 11/4, 2023 at 23:16 Comment(0)
C
2

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()
     });
Cioffred answered 26/5, 2023 at 8:14 Comment(1)
For anyone coming back to this answer due to the flutter_datetime_picker package, the package author is inactive and the project has been forked as flutter_datetime_picker_bdaya by another publisher that is keeping standardsCioffred
G
0

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.

Goeselt answered 10/2, 2023 at 5:4 Comment(0)
B
0

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.

Bergren answered 10/2, 2023 at 5:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.