每次都会随机出字符串
image.png安装依赖 :english_words: ^3.1.0
在pubspace.yaml添加
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
english_words: ^3.1.0
终端命令行执行
flutter packges get
代码
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';//引入模块
void main() => runApp(new MyApp());//ruanAPP
//2点,创建1.StatefulWidget 表示动态的,2.StatelessWidget 表示 不可变的
class RandomWord extends StatefulWidget{
@override
createState() =>new RandomColorState();
}
class RandomColorState extends State<RandomWord>{
@override
Widget build(BuildContext context) {
final wordPair = new WordPair.random();
return new Text(wordPair.asPascalCase);
}
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return new MaterialApp(
title: 'ysfhj',
home: new Scaffold(
appBar: new AppBar(
title: new Text('ssss'),
),
body: new Center(
child: new RandomWord(),//使用它
),
),
);
}
}
送人玫瑰,手留余香。
网友评论