123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import 'package:douyin_demo/providers/recommend_provider.dart';
- import 'package:douyin_demo/views/swiper_main.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_swiper/flutter_swiper.dart';
- import 'package:provider/provider.dart';
- import 'center_image.dart';
- class MainTabView extends StatelessWidget {
- const MainTabView({Key? key}) : super(key: key);
- @override
- Widget build(BuildContext context) {
- RecommendProvider provider = Provider.of<RecommendProvider>(context);
- return TabBarView(
- controller: provider.controller,
- children: [
- SwiperMain(
- type: "关注",
- ),
- SwiperMain(
- type: "推荐",
- ),
- ],
- );
- }
- }
- /// 自定义滑动tab
- class SwiperMain extends StatefulWidget {
- SwiperMain({Key? key, required this.type}) : super(key: key);
- final String type;
- _SwiperMainState createState() => _SwiperMainState();
- }
- class _SwiperMainState extends State<SwiperMain>
- with AutomaticKeepAliveClientMixin {
- @override
- Widget build(BuildContext context) {
- RecommendProvider provider = Provider.of<RecommendProvider>(context);
- List<MainInfo> infos = <MainInfo>[];
- if (widget.type == "followed") {
- infos = provider.followed;
- } else {
- infos = provider.infos;
- }
- return Swiper(
- loop: false,
- scrollDirection: Axis.vertical,
- itemCount: infos.length,
- itemBuilder: (context, index) {
- MainInfo curData = infos[index];
- return Container(
- decoration: BoxDecoration(color: Colors.black),
- child: Stack(children: [
- CenterImage(
- videoPath: curData.videoPath,
- ),
- Home(),
- ]),
- );
- },
- );
- }
- @override
- bool get wantKeepAlive => true;
- }
|