首页 技术 正文
技术 2022年11月20日
0 收藏 646 点赞 2,796 浏览 2616 个字
import 'package:flutter/material.dart';void main() => runApp(MyApp());class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}class _HomePageState extends State<HomePage> {
final PageController ctrl = PageController(
viewportFraction: 0.8,
); List<SliderItem> sliders = [];
String activeTag = 'anime';
int currentPage = 0; @override
void initState() {
super.initState();
_query();
ctrl.addListener(() {
int next = ctrl.page.round();
if (currentPage != next) {
setState(() {
currentPage = next;
});
}
});
} _query({String tag = 'anime'}) {
List<SliderItem> s =
data.where((slider) => slider.tag.contains(tag)).toList(); print(s.length);
setState(() {
sliders = s;
activeTag = tag;
});
} @override
Widget build(BuildContext context) {
return Scaffold(
body: PageView.builder(
itemBuilder: (context, int index) {
if (index == 0) {
return _buildTagPage();
} else if (sliders.length >= index) {
bool active = currentPage == index;
return _buildStoryPage(sliders[index - 1], active);
} else {
return Text('Not Data.');
}
},
scrollDirection: Axis.horizontal,
controller: ctrl,
itemCount: sliders.length + 1,
),
);
} _buildButton(String tag) {
Color color = tag == activeTag ? Colors.purple : Colors.white;
return FlatButton(
color: color,
child: Text('#$tag'),
onPressed: () => _query(tag: tag),
);
} Widget _buildTagPage() {
return Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'选择你喜欢的标签: ',
style: Theme.of(context).textTheme.title,
),
_buildButton('anime'),
_buildButton('girl'),
_buildButton('jojo'),
],
),
);
} Widget _buildStoryPage(SliderItem slider, bool active) {
final double blur = active ? 30 : 0;
final double offset = active ? 20 : 0;
final double top = active ? 100 : 200;
return AnimatedContainer(
duration: Duration(milliseconds: 500),
curve: Curves.easeOutQuint,
margin: EdgeInsets.only(top: top, left: 10, right: 10, bottom: 24),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
image: DecorationImage(
image: NetworkImage(slider.img),
fit: BoxFit.cover,
),
boxShadow: [
BoxShadow(
color: Colors.black87,
blurRadius: blur,
offset: Offset(offset, offset),
),
],
),
child: Center(
child: Text(
slider.title,
style: TextStyle(
fontSize: 40,
color: Colors.white,
),
),
),
);
}
}List<SliderItem> data = [
SliderItem(
img: 'https://img.zhankr.net/yvkowof3uet266352.png',
tag: ['anime', 'girl'],
title: 'Anime1',
),
SliderItem(
img: 'https://img.zhankr.net/gnxq1ctavsy266353.png',
tag: ['anime', 'girl'],
title: 'Anime2',
),
SliderItem(
img: 'https://img.zhankr.net/53veezsqrwq266354.png',
tag: ['anime', 'jojo'],
title: 'Anime3',
),
];class SliderItem {
SliderItem({this.img, this.tag, this.title});
final String img;
final List<String> tag;
final String title;
}
上一篇: nasm astrcat函数 x86
下一篇: MySQL 修改数据表
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,075
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,551
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,399
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,811
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,893