SlideView.dart 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import 'package:flutter/material.dart';
  2. import '../pages/NewsDetailPage.dart';
  3. class SlideView extends StatefulWidget {
  4. var data;
  5. SlideView(data) {
  6. this.data = data;
  7. }
  8. @override
  9. State<StatefulWidget> createState() {
  10. return new SlideViewState(data);
  11. }
  12. }
  13. class SlideViewState extends State<SlideView> with SingleTickerProviderStateMixin {
  14. TabController tabController;
  15. List slideData;
  16. SlideViewState(data) {
  17. slideData = data;
  18. }
  19. @override
  20. void initState() {
  21. super.initState();
  22. tabController = new TabController(length: slideData == null ? 0 : slideData.length, vsync: this);
  23. }
  24. @override
  25. void dispose() {
  26. tabController.dispose();
  27. super.dispose();
  28. }
  29. Widget generateCard() {
  30. return new Card(
  31. color: Colors.blue,
  32. child: new Image.asset("images/ic_avatar_default.png", width: 20.0, height: 20.0,),
  33. );
  34. }
  35. @override
  36. Widget build(BuildContext context) {
  37. List<Widget> items = [];
  38. if (slideData != null && slideData.length > 0) {
  39. for (var i = 0; i < slideData.length; i++) {
  40. var item = slideData[i];
  41. var imgUrl = item['imgUrl'];
  42. var title = item['title'];
  43. var detailUrl = item['detailUrl'];
  44. items.add(new GestureDetector(
  45. onTap: () {
  46. // 点击跳转到详情
  47. Navigator.of(context).push(new MaterialPageRoute(
  48. builder: (ctx) => new NewsDetailPage(id: detailUrl)
  49. ));
  50. },
  51. child: new Stack(
  52. children: <Widget>[
  53. new Image.network(imgUrl),
  54. new Container(
  55. width: MediaQuery.of(context).size.width,
  56. color: const Color(0x50000000),
  57. child: new Padding(
  58. padding: const EdgeInsets.all(6.0),
  59. child: new Text(title, style: new TextStyle(color: Colors.white, fontSize: 15.0)),
  60. )
  61. )
  62. ],
  63. ),
  64. ));
  65. }
  66. }
  67. return new TabBarView(
  68. controller: tabController,
  69. children: items,
  70. );
  71. }
  72. }