Custom library
import ’lib/xxx.dart'
System built-in library
import ‘dart:math'
import 'dart:io'
Pub package management system library
pub warehouse address:
https://pub.dev/packages
https://pub.flutter-io.cn/packages
- Create a new pubspec.yaml file in the root directory of your own project
- Configure the name, description, dependencies and other information in the pubspec.yaml file
- Run pub get to download the package to the local
- Introduce the library import 'package: http / http.dart' as http in the project
For example, if we want to find http dependencies from pub, we directly open the pub warehouse address:
directly search to find the version corresponding to http, and add the http dependency to the pubspec.yaml file
name: xxx
description: A flutter module
dependencies:
http: ^0.12.0+4
After the pub get installation is completed, then follow the example in the warehouse and refer to your own code:
Package conflict resolution
If the same class is defined in the two dart files introduced, then we use as to resolve the conflict
import 'lib/Person1.dart';
import 'lib/Person2.dart' as per;
main(List<String> args) {
Person person = new Person();
per.Person person2 = new per.Person();
}
Both Person1 and Person2 define the class of Person. If you do not apply as at the same time, you will get an error when creating the Person class. After using as, you will clearly specify the Person class in the dart file when you create it. Too.
Import some methods
Use the show keyword to refer to a method in a dart file
import 'lib/MyMath.dart' show getName