Class name conflict resolution method of 2 libraries in Flutter

Class name conflict resolution method of 2 libraries in Flutter


For example, when we use internationalization, we will set a local attribute for the component (such as the calendar component) to display the local language:

locale: Locale("zh")

In the above example, Chinese is displayed.

When we use the third-party library date_format to format the date, since the locale component is also included in the date_format library, an error will be reported.

Insert picture description here

Solution

Create an alias for any of the two conflicting libraries to solve the problem.

For example, here we create an alias dataFormat for the date_format library:

import 'package:date_format/date_format.dart' as dataFormat;

In the code, use aliases:

dataFormat.formatDate(picker, ['yyyy', '-', 'mm', '-', 'dd']);

The conflict problem is resolved.


**PS: For more exciting content, please check --> "Flutter Development"
**PS: For more exciting content, please check --> "Flutter Development"
**PS: For more exciting content, please check --> "Flutter Development"

Guess you like

Origin blog.csdn.net/u011578734/article/details/111871864