SameCityPage.dart 6.5 KB

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