Extensions: Handling Conflicts
Learn to handle conflicts in similar named extensions.
We'll cover the following...
What Is a Conflict?
Imagine that you have a library/file to hold all common extensions of a project. Let’s say this file is called ‘extensions_lib.dart’.
The ‘extensions_lib’ has two extensions:
- An extension on
List
type namedMyList
. - An extension on
double
type namedMyDouble
.
MyList
Extension
The MyList
extension defines a method firstItem()
that returns the first element of the list. The return type is generic which is also represented as T
. You will learn more about generics later in the course.
extension MyList<T> on List<T> {
//Returns the first item in this list
T first() => this[0];
}
MyDouble
extension
The MyDouble
...