//引用自定义库 使用show来专门引用库内的某个方法
import 'lib/TestLib.dart' show testLib;
//系统内置库
import 'dart:math';
//第三方库
import 'dart:convert' as convert;
import 'package:http/http.dart' as http;
/**
* 在Dart中,库的使用可以用import关键字引入 和java类似
* 在Dart中,库的使用时通过import关键字引入的。
* library指令可以创建一个库,每个Dart文件都是一个库,即使没有使用library指令来指定。
Dart中的库主要有三种:
1、我们自定义的库
import ' lib/xxx. dart';I
2、系统内置库
import ' dart :math' ;
import ' dart:io' ;
import ' dart: convert ' ;
3、Pub包管理系统中的库
https://pub.dev/packages
https://pub.flutter-io.cn/packages
https://pub.dartlang.org/flutter/
1、需要在自己项目根目录新建个pubspec.yaml
2、在pubspec .yaml文件然后配置名称、描述、依赖等信息
3、然后运行pub get获取包下载到本地
4、项目中引入库import ' package :http/http.dart' as http; 看文档使用
*/
/**
* 因为main方法里用到了await 所以main方法必须定义为async
*/
void main()async{
/**
* 调用自定义库的方法
*/
testLib();
/**
* 系统内置库 求最小数
*/
print(min(1,2));
/**
* 使用第三方库http调用api接口
*/
// This example uses the Google Books API to search for books about http.
// https://www.huobi.br.com/-/x/pro/market/overview5
var url = "https://www.huobi.br.com/-/x/pro/market/overview5";
// Await the http get response, then decode the json-formatted responce.
var response = await http.get(url);
if (response.statusCode == 200) {
print(convert.jsonDecode(response.body));
} else {
print("Request failed with status: ${response.statusCode}.");
}
}
pubspec.yaml:
name: dart_base
description: A new Flutter application.
dependencies:
http: ^0.12.0+2