12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- import 'package:flutter/material.dart';
- import '../pages/news_detail_page.dart';
- class SlideView extends StatefulWidget {
- var data;
- SlideView(data) {
- this.data = data;
- }
- @override
- State<StatefulWidget> createState() {
- return SlideViewState(data);
- }
- }
- class SlideViewState extends State<SlideView> with SingleTickerProviderStateMixin {
- TabController? tabController;
- List? slideData;
- SlideViewState(data) {
- slideData = data;
- }
- @override
- void initState() {
- super.initState();
- tabController = TabController(length: slideData == null ? 0 : slideData!.length, vsync: this);
- }
- @override
- void dispose() {
- tabController!.dispose();
- super.dispose();
- }
- Widget generateCard() {
- return Card(
- color: Colors.blue,
- child: Image.asset("images/ic_avatar_default.png", width: 20.0, height: 20.0,),
- );
- }
- @override
- Widget build(BuildContext context) {
- List<Widget> items = [];
- if (slideData != null && slideData!.length > 0) {
- for (var i = 0; i < slideData!.length; i++) {
- var item = slideData![i];
- var imgUrl = item['imgUrl'];
- var title = item['title'];
- var detailUrl = item['detailUrl'];
- items.add(GestureDetector(
- onTap: () {
- // 点击跳转到详情
- Navigator.of(context).push(MaterialPageRoute(
- builder: (ctx) => NewsDetailPage(id: detailUrl)
- ));
- },
- child: Stack(
- children: [
- Image.network(imgUrl),
- Container(
- width: MediaQuery.of(context).size.width,
- color: const Color(0x50000000),
- child: Padding(
- padding: const EdgeInsets.all(6.0),
- child: Text(title, style: TextStyle(color: Colors.white, fontSize: 15.0)),
- )
- )
- ],
- ),
- ));
- }
- }
- return TabBarView(
- controller: tabController,
- children: items,
- );
- }
- }
|