flutter最简单的天气预报
项目结构
介绍
预览图
- 首页
- 左右滑动的导航条
- 下拉刷新
- 未来七天的天气
- 未来七天天气的刷新
代码
代码链接:flutter最简单的天气预报
逻辑
- 封装天气
static const forecast = {
0: Icons.wb_sunny_outlined,
1: Icons.cloud_queue,
2: Icons.ac_unit,
3: Icons.flash_on,
4: Icons.waves,
};
- 封装日期
class listview extends State {
SecondScreen sec = new SecondScreen();
static const date = {
0: "今天",
1: "星期二",
2: "星期三",
3: "星期四",
4: "星期五",
5: "星期六",
6: "星期日",
};
- 封装随机温度
randomBit(int len) {
String scopeF = '1'; //首位
String scopeC = '0123456789'; //中间
String scopeD = '01234';
String result = '';
if (len == 2) {
for (int i = 0; i < len; i++) {
if (i == 0) {
result = scopeF[Random().nextInt(scopeF.length)];
} else {
result = result + scopeC[Random().nextInt(scopeC.length)];
}
}
return result;
} else {
for (int i = 0; i < len; i++)
result = result + scopeD[Random().nextInt(scopeD.length)];
return result;
}
}