https://pub.dev/flutter is Google's official Dart Packages warehouse, similar to the npm warehouse in node, we can find the packages and plug-ins we need on it, and we can also publish our packages and plug-ins to pub, which we use
here One is called english_words , it contains thousands of commonly used English words and provides some functions for comparison,
add dependencies
Add dependencies in pubspec.yaml file
pubspec.yaml
We save the pubspec.yaml file, which will automatically install the dependency package into the project, and the console outputs the following content
console output
Next we can use this dependency package
lib/main.dart
import 'package:flutter/material.dart';
//引入english_words
import 'package:english_words/english_words.dart';
//main是入口函数
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// 生成一个随机的单词
final wordPair = new WordPair.random();
return new MaterialApp(
title: 'Hello Flutter',
home: new Scaffold(
appBar: new AppBar(
title: new Text('Hello Flutter Title'),
),
body: new Center(
child: new Text(wordPair.asPascalCase), //asPascalCase以简单字符串的形式返回单词对,每个单词大写
),
),
);
}
}
In this way, every time we press R, the page re-renders, we will see a random English word
If the version sdk does not match, modify the plug-in version number to match your own dartsdk
environment: sdk: ">=2.0.0-dev.68.0 <3.0.0"
Author: iDevOps
Link: https://www.jianshu.com/p/47143557a550
Source: Jianshu
The copyright belongs to the author. For commercial reprint, please contact the author for authorization, for non-commercial reprint, please indicate the source.