home_page.dart 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import 'dart:ui';
  2. import 'package:amap_base/amap_base.dart';
  3. import 'package:fluro/fluro.dart';
  4. import 'package:flutter/cupertino.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter_easyrefresh/ball_pulse_footer.dart';
  7. import 'package:flutter_easyrefresh/ball_pulse_header.dart';
  8. import 'package:flutter_easyrefresh/easy_refresh.dart';
  9. import 'package:flutter_note/routers/application.dart';
  10. import 'package:flutter_note/views/homepage/ad_banner.dart';
  11. import 'package:flutter_note/views/homepage/banner_diy.dart';
  12. import 'package:flutter_note/views/homepage/floor_part.dart';
  13. import 'package:flutter_note/views/homepage/hot_part.dart';
  14. import 'package:flutter_note/views/homepage/lead_phone.dart';
  15. import 'package:flutter_note/views/homepage/mall_recommend.dart';
  16. import 'package:flutter_note/views/homepage/top_nativator.dart';
  17. import 'package:flutter_note/provide/home_provide.dart';
  18. import 'package:flutter_note/routers/routers.dart';
  19. import 'package:provide/provide.dart';
  20. class HomePage extends StatelessWidget {
  21. final GlobalKey<EasyRefreshState> _refreshKey = GlobalKey();
  22. final GlobalKey<RefreshHeaderState> _headerKey = GlobalKey();
  23. final GlobalKey<RefreshFooterState> _footerKey = GlobalKey();
  24. final ScrollController _outController = ScrollController();
  25. final _mapLocation = AMapLocation();
  26. @override
  27. Widget build(BuildContext context) {
  28. _mapLocation.init();
  29. Permissions().requestPermission().then((granted) {
  30. if (granted) {
  31. _mapLocation
  32. .getLocation(LocationClientOptions(
  33. isOnceLocation: true,
  34. isNeedAddress: true,
  35. locatingWithReGeocode: true,
  36. ))
  37. .then((location) {
  38. print(
  39. 'location:(${location.longitude}, ${location.latitude}), ${location.district}');
  40. Provide.value<HomeProvide>(context)
  41. ..initHomeEntity(location.longitude, location.latitude)
  42. ..changeDistrict(
  43. location.district, location.longitude, location.latitude);
  44. });
  45. } else {
  46. Provide.value<HomeProvide>(context).initHomeEntity(115.02932, 35.76189);
  47. }
  48. });
  49. Provide.value<HomeProvide>(context).initHotGoodsList();
  50. _outController.addListener(() {
  51. Provide.value<HomeProvide>(context).enableBack(
  52. _outController.position.pixels >= window.physicalSize.height);
  53. });
  54. return Theme(
  55. data: ThemeData(
  56. primarySwatch: Colors.pink,
  57. iconTheme: IconThemeData(color: Colors.pink)),
  58. child: Provide<HomeProvide>(
  59. builder: (_, widget, homeProvide) => Scaffold(
  60. appBar: AppBar(
  61. title: Text('百姓生活+'),
  62. centerTitle: true,
  63. leading: InkWell(
  64. child: Padding(
  65. padding: const EdgeInsets.all(4.0),
  66. child: Row(
  67. children: <Widget>[
  68. Icon(Icons.location_on,
  69. color: Colors.white, size: 12.0),
  70. Expanded(
  71. child: Text(homeProvide.district,
  72. style: TextStyle(fontSize: 12.0),
  73. overflow: TextOverflow.ellipsis,
  74. maxLines: 1),
  75. )
  76. ],
  77. ),
  78. ),
  79. onTap: () => Application.router.navigateTo(
  80. context, Routers.map,
  81. transition: TransitionType.fadeIn),
  82. ),
  83. ),
  84. body: homeProvide.homeEntity == null
  85. ? Center(child: CupertinoActivityIndicator(radius: 12.0))
  86. : EasyRefresh(
  87. key: _refreshKey,
  88. refreshHeader: BallPulseHeader(
  89. key: _headerKey, color: Colors.pink),
  90. refreshFooter: BallPulseFooter(
  91. key: _footerKey, color: Colors.pink),
  92. loadMore: () => homeProvide.loadMoreHotGoods(),
  93. child: CustomScrollView(
  94. controller: _outController,
  95. physics: BouncingScrollPhysics(),
  96. slivers: <Widget>[
  97. BannerDiy(
  98. bannerImages:
  99. homeProvide.homeEntity.data.slides),
  100. TopNavigatorBar(
  101. categories:
  102. homeProvide.homeEntity.data.category),
  103. AdBanner(
  104. bannerUrl: homeProvide.homeEntity.data
  105. .advertesPicture.pICTUREADDRESS),
  106. LeaderPhone(
  107. imageUrl: homeProvide
  108. .homeEntity.data.shopInfo.leaderImage,
  109. phone: homeProvide
  110. .homeEntity.data.shopInfo.leaderPhone,
  111. ),
  112. RecommendWidget(
  113. recommendList:
  114. homeProvide.homeEntity.data.recommend),
  115. FloorTitle(
  116. floorPic: homeProvide
  117. .homeEntity.data.floor1Pic.pICTUREADDRESS),
  118. FloorContent(
  119. floorContent:
  120. homeProvide.homeEntity.data.floor1),
  121. FloorTitle(
  122. floorPic: homeProvide
  123. .homeEntity.data.floor2Pic.pICTUREADDRESS),
  124. FloorContent(
  125. floorContent:
  126. homeProvide.homeEntity.data.floor2),
  127. FloorTitle(
  128. floorPic: homeProvide
  129. .homeEntity.data.floor3Pic.pICTUREADDRESS),
  130. FloorContent(
  131. floorContent:
  132. homeProvide.homeEntity.data.floor3),
  133. HotGoodsTitle(),
  134. SliverGrid.count(
  135. crossAxisCount: 2,
  136. childAspectRatio: 0.7,
  137. children: homeProvide.hodGoodsList
  138. .map((hot) => HotItem(hot: hot))
  139. .toList(),
  140. )
  141. ],
  142. ),
  143. ),
  144. floatingActionButton: homeProvide.showBack
  145. ? FloatingActionButton(
  146. onPressed: () {
  147. _outController.animateTo(0.0,
  148. duration: Duration(milliseconds: 500),
  149. curve: Curves.decelerate);
  150. },
  151. mini: true,
  152. child: Icon(Icons.vertical_align_top))
  153. : null,
  154. )),
  155. );
  156. }
  157. }