基础组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

122 lines
3.2 KiB

  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:zhiying_base_widget/pages/main_page/main_page.dart';
  4. class MinePage extends StatefulWidget {
  5. @override
  6. _MinePageState createState() => _MinePageState();
  7. }
  8. class _MinePageState extends State<MinePage> with TickerProviderStateMixin {
  9. TabController _tabController;
  10. Map<String, dynamic> _datas = Map();
  11. @override
  12. void initState() {
  13. _tabController = TabController(length: 3, vsync: this);
  14. // 模拟数据
  15. List<Map<String, dynamic>> list = List();
  16. list.add(
  17. Map<String, dynamic>.from({'mod_name': 'index_search', 'mod_id': 5}));
  18. list.add(
  19. Map<String, dynamic>.from({'mod_name': 'index_carousel', 'mod_id': 6}));
  20. list.add(Map<String, dynamic>.from({'mod_name': 'multi_nav', 'mod_id': 7}));
  21. list.add(Map<String, dynamic>.from(
  22. {'mod_name': 'index_banner_one', 'mod_id': 8}));
  23. list.add(Map<String, dynamic>.from(
  24. {'mod_name': 'index_banner_two', 'mod_id': 9}));
  25. list.add(Map<String, dynamic>.from(
  26. {'mod_name': 'index_recommend_list', 'mod_id': 10}));
  27. _datas['components'] = list;
  28. super.initState();
  29. }
  30. @override
  31. void dispose() {
  32. _tabController.dispose();
  33. super.dispose();
  34. }
  35. @override
  36. Widget build(BuildContext context) {
  37. List<Widget> _silverBuilder(BuildContext context, bool innerBoxIsScrolled) {
  38. return <Widget>[
  39. SliverAppBar(),
  40. SliverPersistentHeader(
  41. pinned: true,
  42. delegate: _SilverAppBarDelegate(
  43. Container(
  44. color: Colors.amber,
  45. child: TabBar(
  46. labelColor: Colors.blue,
  47. unselectedLabelColor: Colors.black,
  48. controller: _tabController,
  49. tabs: <Widget>[
  50. new Tab(
  51. text: "tab10",
  52. ),
  53. new Tab(
  54. text: "tab2",
  55. ),
  56. new Tab(
  57. text: "tab3",
  58. ),
  59. ],
  60. ),
  61. ),
  62. ),
  63. ),
  64. ];
  65. }
  66. return Scaffold(
  67. body: SafeArea(
  68. child: NestedScrollView(
  69. headerSliverBuilder: _silverBuilder,
  70. body: TabBarView(
  71. controller: _tabController,
  72. children: <Widget>[
  73. MainPage(_datas),
  74. ListView.builder(
  75. itemCount: 50,
  76. itemBuilder: (context, count) {
  77. return Container(
  78. height: 50,
  79. color: Colors.primaries[count % Colors.primaries.length],
  80. child: Text('aaaaa ${count.toString()}'),
  81. );
  82. }),
  83. MainPage(_datas),
  84. ],
  85. ),
  86. )),
  87. );
  88. }
  89. }
  90. class _SilverAppBarDelegate extends SliverPersistentHeaderDelegate {
  91. _SilverAppBarDelegate(this.child);
  92. final Widget child;
  93. @override
  94. double get minExtent => 44;
  95. @override
  96. double get maxExtent => 44;
  97. @override
  98. Widget build(
  99. BuildContext context, double shrinkOffset, bool overlapsContent) {
  100. return new Container(
  101. child: child,
  102. );
  103. }
  104. @override
  105. bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) {
  106. return false;
  107. }
  108. }