SameCityPage.dart 6.2 KB

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