home_page.dart 2.92 KB
import 'package:Parlando/poem/components/video_slides.dart';
import 'package:flutter/material.dart';

class Home extends StatefulWidget {
  const Home({Key? key}) : super(key: key);

  @override
  HomeState createState() => HomeState();
}

class HomeState extends State<Home> {
  final PageController _controller = PageController();

  @override
  void initState() {
    super.initState();
    //设置pageView 滑动监听
    _controller.addListener(() {
      if (_controller.position.pixels == _controller.position.maxScrollExtent) {
        print('滑动到了最底部');
        _getMore();
      }
    });
  }

  /// 下拉刷新方法,为list重新赋值
  Future<void> _onRefresh() async {
    await Future.delayed(const Duration(seconds: 1), () {
      print('refresh');
      setState(() {});
    });
  }

  /// 上拉加载更多
  Future<void> _getMore() async {
    await Future.delayed(const Duration(seconds: 1), () {
      print('_getMore');
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        RefreshIndicator(
          //下拉刷新触发方法
          onRefresh: _onRefresh,
          //设置listView
          child: PageView(
            controller: _controller,
            //设置滑动方向
            scrollDirection: Axis.vertical,
            children: const [
              VideoSlides(),
              VideoSlides(),
              VideoSlides(),
            ],
          ),
        ),
        Positioned(
          top: 18.0,
          left: 10.0,
          right: 10.0,
          child: Center(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                TextButton(
                  onPressed: () {},
                  child: const Text(
                    "临境",
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 15,
                    ),
                  ),
                ),
                const Text(
                  "|",
                  style: TextStyle(color: Colors.white),
                ),
                TextButton(
                  onPressed: () {},
                  child: const Text(
                    "妙众",
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 15,
                    ),
                  ),
                ),
                const Text(
                  "|",
                  style: TextStyle(color: Colors.white),
                ),
                TextButton(
                  onPressed: () => {},
                  child: const Text(
                    "新鲜",
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 15,
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ],
    );
  }
}