same_city_page.dart 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import 'package:douyin_demo/model/posts_model.dart';
  2. import 'package:douyin_demo/providers/PostsGalleryProvider.dart';
  3. import 'package:douyin_demo/widgets/bottom_bar.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:provider/provider.dart';
  6. /// Description: 同城
  7. /// Time : 04/05/2022 Tuesday
  8. /// Author : liuyuqi.gov@msn.cn
  9. class SameCityMain extends StatelessWidget {
  10. const SameCityMain({Key? key, required this.selIndex}) : super(key: key);
  11. final int selIndex;
  12. @override
  13. Widget build(BuildContext context) {
  14. PostsGalleryProvider provider =
  15. Provider.of<PostsGalleryProvider>(context); //null
  16. double rpx = MediaQuery.of(context).size.width / 750;
  17. ScrollController controller = ScrollController();
  18. return provider.model1 == null
  19. ? Scaffold(
  20. // body: Loading(),
  21. )
  22. : Scaffold(
  23. backgroundColor: Theme.of(context).primaryColor,
  24. appBar: AppBar(
  25. title: Text("同城"),
  26. ),
  27. bottomNavigationBar: Container(
  28. decoration: BoxDecoration(color: Colors.black),
  29. child: SafeArea(child: BtmBar(selectIndex: selIndex))),
  30. body: Column(
  31. mainAxisSize: MainAxisSize.min,
  32. children: [
  33. Container(
  34. height: 120 * rpx,
  35. padding: EdgeInsets.all(20 * rpx),
  36. child: Row(
  37. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  38. children: [
  39. Row(
  40. children: [
  41. Icon(
  42. Icons.near_me,
  43. color: Colors.grey[400],
  44. ),
  45. Text(
  46. "自动定位 :上海",
  47. style: TextStyle(color: Colors.grey[400]),
  48. ),
  49. ],
  50. ),
  51. Row(
  52. children: [
  53. Text("切换",
  54. style: TextStyle(color: Colors.grey[400])),
  55. Icon(Icons.arrow_right, color: Colors.grey[400])
  56. ],
  57. ),
  58. ],
  59. )),
  60. Expanded(
  61. child: SingleChildScrollView(
  62. controller: controller,
  63. child: Container(
  64. padding: EdgeInsets.symmetric(horizontal: 10 * rpx),
  65. child: Row(
  66. crossAxisAlignment: CrossAxisAlignment.start,
  67. children: [
  68. Flexible(
  69. flex: 1,
  70. child: WaterFallList(
  71. dataList: provider.model1,
  72. controller: controller,
  73. )),
  74. Flexible(
  75. flex: 1,
  76. child: WaterFallList(
  77. dataList: provider.model2,
  78. controller: controller),
  79. ),
  80. ],
  81. ))))
  82. ],
  83. ),
  84. );
  85. }
  86. }
  87. class WaterFallList extends StatelessWidget {
  88. const WaterFallList({Key? key, required this.dataList, required this.controller})
  89. : super(key: key);
  90. final List<PostsModel> dataList;
  91. final ScrollController controller;
  92. @override
  93. Widget build(BuildContext context) {
  94. double rpx = MediaQuery.of(context).size.width / 750;
  95. double outPadding = 10 * rpx;
  96. double eachSide = 2 * rpx;
  97. return ListView.builder(
  98. controller: controller,
  99. shrinkWrap: true,
  100. itemCount: dataList.length,
  101. itemBuilder: (context, index) {
  102. PostsModel curPosts = dataList[index];
  103. return Container(
  104. margin: EdgeInsets.only(bottom: 10 * rpx),
  105. child: Column(
  106. mainAxisSize: MainAxisSize.min,
  107. children: [
  108. Stack(
  109. children: [
  110. Container(
  111. width: 345 * rpx,
  112. padding: EdgeInsets.symmetric(horizontal: eachSide),
  113. height: 345 * curPosts.picsRate * rpx,
  114. child: Image.network(
  115. "https://www.guojio.com/" + curPosts.postsPics,
  116. fit: BoxFit.fitWidth,
  117. )),
  118. Positioned(
  119. bottom: 0,
  120. child: Container(
  121. width: 345 * rpx,
  122. height: 60 * rpx,
  123. padding: EdgeInsets.all(eachSide + 10 * rpx),
  124. child: Row(
  125. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  126. children: [
  127. Row(
  128. children: [
  129. Icon(
  130. Icons.near_me,
  131. color: Colors.grey[400],
  132. size: 32 * rpx,
  133. ),
  134. Text(
  135. "1km",
  136. style: TextStyle(
  137. color: Colors.grey[400],
  138. fontSize: 26 * rpx),
  139. ),
  140. ],
  141. ),
  142. Container(
  143. width: 40 * rpx,
  144. height: 40 * rpx,
  145. child: CircleAvatar(
  146. backgroundImage: NetworkImage(
  147. curPosts.makerPhoto,
  148. )))
  149. ],
  150. )),
  151. )
  152. ],
  153. ),
  154. Container(
  155. padding: EdgeInsets.all(10 * rpx),
  156. child: Text(
  157. curPosts.postsContent,
  158. maxLines: 3,
  159. overflow: TextOverflow.ellipsis,
  160. style: TextStyle(color: Colors.white, fontSize: 26 * rpx),
  161. ))
  162. ],
  163. ));
  164. },
  165. );
  166. }
  167. }