android flutter 3.使用使用外部包 例子

公开资源包
https://pub.dartlang.org/flutter/

例子

添加 english_words

1 pubspec.yaml中添加

1
2
3
4
5
6
dependencies:
flutter:
sdk: flutter

cupertino_icons: ^0.1.0
english_words: ^3.1.0 # add this line

2 更新 package
点击 Packages get

3 .dart文件中引入package

1
2
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';

4 使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';

/// MySnapPage
class extends StatefulWidget {

_MySnapPageState createState() => new _MySnapPageState();
}

class _MySnapPageState extends State<> {

Widget build(BuildContext context) {

final wordPair = new WordPair.random();

return new Scaffold(
// appBar: new AppBar(title: new Text("MySnapPage"),),
// body: new Center(child: new Text("MySnapPage")),
body: new Center(child: new Text(wordPair.asPascalCase) ),

);
}
}

创建WordPair

1
final wordPair = new WordPair.random(); 

使用wordPair

new Text(wordPair.asPascalCase)