Why flutter give an error 'Undefined name DateFormat"?

2.6k Views Asked by At

How can I fix it? Please don't say import intl.dart as you can see at the second photo I already add it.

1

2

3

There are 3 best solutions below

0
tguzel On BEST ANSWER

It might be using the Date Format class from another package.

-> import 'package:intl/intl.dart' as intl;

Edit the import like this.

Try using the date format as below.

intl.DateFormat.yMMMd().format(transaction[index].date),

0
Ivo On

Your import statement has a red line under it. Meaning it has an error. Most likely you didn't include intl in your dependencies. You need to add this in the dependencies section of your pubspec.yaml file.

intl: ^0.17.0
0
editix On

Open your terminal in VSCode (Ctrl + Shift + ') then type flutter pub add intl to add the intl package on your dependencies.