Dart: Classification of libraries in Dart


foreword

This article introduces the library-related knowledge points in Dart

1. Libraries in Dart

In Dart,
the library instruction introduced by the import keyword can create a library when using the library, and each Dart file is a library, even if the library instruction is not used to specify

There are three libraries in Dart, as follows

system-defined library

import ‘lib/xxx.dart’;

System built-in library

import ‘dart:math’;
import ‘dart:io’;

third party library

Third-party library source

Find the library to use from the following URL
https://pub.dev/packages
https://pub.flutter-io.cn/pagckages
https://pub.dartlang.org/flutter/

Steps for usage

  • Create a pubspec.yaml file
    name: xxx
    description: A new flutter module project
    depends:
    http:^0.12.0+2
    date_format:^1.0.6
  • Configure dependencies
  • Run pub get to get the remote library
  • See the documentation to import the library to use

2. Dart conflict resolution for renaming libraries in Dart

same library name

当引入两个库中有相同名称标识符的时候,如果是Java通过写上完整的包名路径来解决
	//Drat中的解决方式
	import 'package:lib/lib1.dart';
	import 'package:lib2/lib2.dart as lib2';
	A a = new A();
	lib2.A a2 = new lib2.A();

partial import solution

import 'package:lib/lib1.dart' show xxx方法  
表示只引用该类中的xxx方法,也只能调用xxx方法
show 表示只引用xxx方法
hide 表示隐藏xxx方法,除了xxx方法不可调用以外其他方法皆可调用

Guess you like

Origin blog.csdn.net/qjyws/article/details/128835543