swiper_main.dart 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import 'package:douyin_demo/providers/recommend_provider.dart';
  2. import 'package:douyin_demo/views/rotate_album.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_swiper/flutter_swiper.dart';
  5. import 'package:provider/provider.dart';
  6. import 'btn_content.dart';
  7. import 'button_list.dart';
  8. import 'center_image.dart';
  9. class SwiperMain extends StatefulWidget {
  10. SwiperMain({Key? key, required this.type}) : super(key: key);
  11. final String type;
  12. _SwiperMainState createState() => _SwiperMainState();
  13. }
  14. class _SwiperMainState extends State<SwiperMain>
  15. with AutomaticKeepAliveClientMixin {
  16. @override
  17. Widget build(BuildContext context) {
  18. RecommendProvider provider = Provider.of<RecommendProvider>(context);
  19. List<MainInfo> infos = <MainInfo>[];
  20. if (widget.type == "followed") {
  21. infos = provider.followed;
  22. } else {
  23. infos = provider.infos;
  24. }
  25. return Swiper(
  26. loop: false,
  27. scrollDirection: Axis.vertical,
  28. itemCount: infos.length,
  29. itemBuilder: (context, index) {
  30. MainInfo curData = infos[index];
  31. return Container(
  32. decoration: BoxDecoration(color: Colors.black),
  33. child: Stack(children: [
  34. CenterImage(
  35. videoPath: curData.videoPath,
  36. ),
  37. Home(),
  38. ]),
  39. );
  40. },
  41. );
  42. }
  43. @override
  44. bool get wantKeepAlive => true;
  45. }
  46. class Home extends StatelessWidget {
  47. const Home({Key? key}) : super(key: key);
  48. @override
  49. Widget build(BuildContext context) {
  50. double screenWidth = MediaQuery.of(context).size.width;
  51. double screenHeight = MediaQuery.of(context).size.height;
  52. RecommendProvider provider = Provider.of<RecommendProvider>(context);
  53. double rpx = screenWidth / 750;
  54. return Stack(children: [
  55. Positioned(
  56. bottom: 0,
  57. width: 0.70 * screenWidth,
  58. height: 260 * rpx,
  59. child: Container(
  60. // decoration: BoxDecoration(color: Colors.redAccent),
  61. child: BtnContent(),
  62. ),
  63. ),
  64. Positioned(
  65. right: 0,
  66. width: 0.2 * screenWidth,
  67. height: 500 * rpx,
  68. top: 0.45 * screenHeight,
  69. child: Container(
  70. // decoration: BoxDecoration(color: Colors.orangeAccent),
  71. child: ButtonList(),
  72. ),
  73. ),
  74. Positioned(
  75. bottom: 20 * rpx,
  76. right: 0,
  77. width: 0.2 * screenWidth,
  78. height: 0.2 * screenWidth,
  79. child: Container(
  80. // decoration: BoxDecoration(color: Colors.purpleAccent),
  81. child: RotateAlbum(),
  82. ),
  83. )
  84. ]);
  85. }
  86. }