logo头像
Snippet 博客主题

android Flutter 3.使用使用外部包

本文于375天之前发表,文中内容可能已经过时。

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'; // Add this line.

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'; // Add this line.

/// MySnapPage
class MySnapPage extends StatefulWidget {
@override
_MySnapPageState createState() => new _MySnapPageState();
}

class _MySnapPageState extends State<MySnapPage> {
@override
Widget build(BuildContext context) {

final wordPair = new WordPair.random(); // Add this line.

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(); // Add this line.

使用wordPair

new Text(wordPair.asPascalCase)
支付宝打赏 微信打赏

打赏