1.包仓库
首先展示一个包仓库,有需要的,可以去包仓库中去搜索需要的导包
https://pub.dev/
2.导包的使用案例
添加依赖包的位置在pubspec.yaml
文件中,在dependencies
下添加包的名称和版本号url_launcher: ^4.0.1
,代码示例如下:
name: frist_flutter_app
description: A new Flutter project.
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
# 添加依赖包的名称
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
url_launcher: ^4.0.1
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
依赖添加完成之后,要在文件中进行导入import 'package:url_launcher/url_launcher.dart';
这样在代码中就可以直接引用了,完成代码如下:
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
/**
* 如何使用第三方导包
*/
void main(){
return runApp(new MyInportPackageUse());
}
class MyInportPackageUse extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return new MaterialApp(
title: 'How to use the third-party package example',
home: new Scaffold(
appBar: new AppBar(
title: new Text('How to use the third-party package example'),
),
body: new Center(
child: new RaisedButton(onPressed: (){
//此处指定一个url并发行请求
const url = 'https://www.baidu.com/';
launch(url);
},
child: new Text('Open the url'),),
),
),
);
}
}