|
|
@@ -1,6 +1,9 @@
|
|
|
import 'dart:async';
|
|
|
import 'dart:convert';
|
|
|
|
|
|
+import 'package:address_picker/address_picker.dart';
|
|
|
+import 'package:amap_location/amap_location.dart';
|
|
|
+import 'package:amap_location/amap_location_option.dart';
|
|
|
import 'package:bbyyy/beans/ad_bean_entity.dart';
|
|
|
import 'package:bbyyy/beans/commodity_category_bean_entity.dart';
|
|
|
import 'package:bbyyy/beans/goods_bean_entity.dart';
|
|
|
@@ -22,6 +25,7 @@ import 'package:flutter/cupertino.dart';
|
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
|
import 'package:flutter_swiper/flutter_swiper.dart';
|
|
|
+import 'package:permission_handler/permission_handler.dart';
|
|
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
|
|
|
|
|
class HomePage extends StatefulWidget {
|
|
|
@@ -54,6 +58,9 @@ class _HomePageState extends State<HomePage>
|
|
|
int page = 1;
|
|
|
int pageIndex = 0;
|
|
|
bool showS = false;
|
|
|
+ String province;
|
|
|
+ String city;
|
|
|
+ Address _address;
|
|
|
|
|
|
@override
|
|
|
void initState() {
|
|
|
@@ -79,6 +86,10 @@ class _HomePageState extends State<HomePage>
|
|
|
EventBus().on('商品变动', (arg) {
|
|
|
_reController.requestRefresh();
|
|
|
});
|
|
|
+ EventBus().on('getLocation', (arg) {
|
|
|
+ _reController.requestRefresh();
|
|
|
+ setState(() {});
|
|
|
+ });
|
|
|
_controller.addListener(() {
|
|
|
setState(() {
|
|
|
if (_controller.offset == 0) {
|
|
|
@@ -125,6 +136,7 @@ class _HomePageState extends State<HomePage>
|
|
|
EventBus().off('toTop');
|
|
|
EventBus().off('homeCarousel');
|
|
|
EventBus().off('商品变动');
|
|
|
+ EventBus().off('getLocation');
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
@@ -170,96 +182,290 @@ class _HomePageState extends State<HomePage>
|
|
|
bottom: false,
|
|
|
child: Stack(
|
|
|
children: [
|
|
|
- AnimatedOpacity(
|
|
|
- duration: Duration(milliseconds: 200),
|
|
|
- opacity: showS ? 0.0 : 1.0,
|
|
|
+ // AnimatedOpacity(
|
|
|
+ // duration: Duration(milliseconds: 200),
|
|
|
+ // opacity: showS ? 0.0 : 1.0,
|
|
|
+ // child: Container(
|
|
|
+ // margin: EdgeInsets.only(top: 18),
|
|
|
+ // width: double.infinity,
|
|
|
+ // child: Row(
|
|
|
+ // children: [
|
|
|
+ // GestureDetector(
|
|
|
+ // onTap: () {
|
|
|
+ // setState(() {
|
|
|
+ // pageIndex = 0;
|
|
|
+ // _reController.requestRefresh();
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ // behavior: HitTestBehavior.translucent,
|
|
|
+ // child: Container(
|
|
|
+ // height: 28,
|
|
|
+ // width: 60,
|
|
|
+ // alignment: Alignment.center,
|
|
|
+ // child: Column(
|
|
|
+ // children: [
|
|
|
+ // Text(
|
|
|
+ // '货帮',
|
|
|
+ // style: TextStyle(
|
|
|
+ // color: pageIndex == 0
|
|
|
+ // ? MyColors.cFF4233
|
|
|
+ // : MyColors.c333333,
|
|
|
+ // fontSize: 16,
|
|
|
+ // fontWeight: FontWeight.bold),
|
|
|
+ // ),
|
|
|
+ // Visibility(
|
|
|
+ // child: Container(
|
|
|
+ // width: 32,
|
|
|
+ // height: 2,
|
|
|
+ // decoration: BoxDecoration(
|
|
|
+ // color: MyColors.cFF4233,
|
|
|
+ // borderRadius:
|
|
|
+ // BorderRadius.circular(1)),
|
|
|
+ // ),
|
|
|
+ // visible: pageIndex == 0,
|
|
|
+ // ),
|
|
|
+ // ],
|
|
|
+ // ),
|
|
|
+ // ),
|
|
|
+ // ),
|
|
|
+ // Container(
|
|
|
+ // width: 40,
|
|
|
+ // ),
|
|
|
+ // GestureDetector(
|
|
|
+ // onTap: () {
|
|
|
+ // setState(() {
|
|
|
+ // pageIndex = 1;
|
|
|
+ // _reController.requestRefresh();
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ // behavior: HitTestBehavior.translucent,
|
|
|
+ // child: Container(
|
|
|
+ // height: 28,
|
|
|
+ // width: 60,
|
|
|
+ // alignment: Alignment.center,
|
|
|
+ // child: Column(
|
|
|
+ // children: [
|
|
|
+ // Text(
|
|
|
+ // '商品',
|
|
|
+ // style: TextStyle(
|
|
|
+ // color: pageIndex == 1
|
|
|
+ // ? MyColors.cFF4233
|
|
|
+ // : MyColors.c333333,
|
|
|
+ // fontSize: 16,
|
|
|
+ // fontWeight: FontWeight.bold),
|
|
|
+ // ),
|
|
|
+ // Visibility(
|
|
|
+ // child: Container(
|
|
|
+ // width: 32,
|
|
|
+ // height: 2,
|
|
|
+ // decoration: BoxDecoration(
|
|
|
+ // color: MyColors.cFF4233,
|
|
|
+ // borderRadius:
|
|
|
+ // BorderRadius.circular(1)),
|
|
|
+ // ),
|
|
|
+ // visible: pageIndex == 1,
|
|
|
+ // ),
|
|
|
+ // ],
|
|
|
+ // ),
|
|
|
+ // ),
|
|
|
+ // ),
|
|
|
+ // ],
|
|
|
+ // mainAxisAlignment: MainAxisAlignment.center,
|
|
|
+ // ),
|
|
|
+ // ),
|
|
|
+ // ),
|
|
|
+ Positioned(
|
|
|
+ left: 0,
|
|
|
child: Container(
|
|
|
- margin: EdgeInsets.only(top: 18),
|
|
|
- width: double.infinity,
|
|
|
- child: Row(
|
|
|
- children: [
|
|
|
- GestureDetector(
|
|
|
- onTap: () {
|
|
|
- setState(() {
|
|
|
- pageIndex = 0;
|
|
|
- _reController.requestRefresh();
|
|
|
- });
|
|
|
- },
|
|
|
- behavior: HitTestBehavior.translucent,
|
|
|
- child: Container(
|
|
|
- height: 28,
|
|
|
- width: 60,
|
|
|
- alignment: Alignment.center,
|
|
|
- child: Column(
|
|
|
- children: [
|
|
|
- Text(
|
|
|
- '货帮',
|
|
|
- style: TextStyle(
|
|
|
- color: pageIndex == 0
|
|
|
- ? MyColors.cFF4233
|
|
|
- : MyColors.c333333,
|
|
|
- fontSize: 16,
|
|
|
- fontWeight: FontWeight.bold),
|
|
|
- ),
|
|
|
- Visibility(
|
|
|
- child: Container(
|
|
|
- width: 32,
|
|
|
- height: 2,
|
|
|
- decoration: BoxDecoration(
|
|
|
- color: MyColors.cFF4233,
|
|
|
- borderRadius:
|
|
|
- BorderRadius.circular(1)),
|
|
|
+ padding:
|
|
|
+ EdgeInsets.only(left: 10, right: 10, top: 12),
|
|
|
+ child: GestureDetector(
|
|
|
+ onTap: () {
|
|
|
+ showModalBottomSheet(
|
|
|
+ context: context,
|
|
|
+ builder: (context) => BottomSheet(
|
|
|
+ onClosing: () {},
|
|
|
+ builder: (context) => Container(
|
|
|
+ height: 290,
|
|
|
+ child: Column(
|
|
|
+ children: [
|
|
|
+ Container(
|
|
|
+ height: 40,
|
|
|
+ padding: EdgeInsets.symmetric(
|
|
|
+ horizontal: 15),
|
|
|
+ child: Row(
|
|
|
+ children: [
|
|
|
+ Row(
|
|
|
+ children: [
|
|
|
+ Text(
|
|
|
+ '定位: ',
|
|
|
+ style: TextStyle(
|
|
|
+ color: MyColors.cFF4233,
|
|
|
+ fontSize: 14),
|
|
|
+ ),
|
|
|
+ GestureDetector(
|
|
|
+ onTap: () async {
|
|
|
+ if (MyCookie().location !=
|
|
|
+ null) {
|
|
|
+ province = MyCookie()
|
|
|
+ .location
|
|
|
+ .province;
|
|
|
+ city = MyCookie()
|
|
|
+ .location
|
|
|
+ .city;
|
|
|
+ setState(() {});
|
|
|
+ _reController
|
|
|
+ .requestRefresh();
|
|
|
+ Navigator.pop(context);
|
|
|
+ } else {
|
|
|
+ var locationStatus =
|
|
|
+ await Permission
|
|
|
+ .location
|
|
|
+ .status;
|
|
|
+ if (locationStatus
|
|
|
+ .isDenied) {
|
|
|
+ await Permission
|
|
|
+ .location
|
|
|
+ .request()
|
|
|
+ .then(
|
|
|
+ (value) async {
|
|
|
+ print(
|
|
|
+ 'Permission.location.request()-----$value');
|
|
|
+ if (value ==
|
|
|
+ PermissionStatus
|
|
|
+ .granted) {
|
|
|
+ await AMapLocationClient.startup(
|
|
|
+ new AMapLocationOption(
|
|
|
+ desiredAccuracy:
|
|
|
+ CLLocationAccuracy
|
|
|
+ .kCLLocationAccuracyHundredMeters));
|
|
|
+ await AMapLocationClient
|
|
|
+ .getLocation(
|
|
|
+ true)
|
|
|
+ .then(
|
|
|
+ (value) {
|
|
|
+ MyCookie()
|
|
|
+ .location =
|
|
|
+ value;
|
|
|
+ EventBus().emit(
|
|
|
+ 'getLocation');
|
|
|
+ _reController
|
|
|
+ .requestRefresh();
|
|
|
+ Navigator.pop(
|
|
|
+ context);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ behavior: HitTestBehavior
|
|
|
+ .translucent,
|
|
|
+ child: Text(
|
|
|
+ MyCookie().location !=
|
|
|
+ null
|
|
|
+ ? '${MyCookie().location.province} ${MyCookie().location.city}'
|
|
|
+ : '获取定位',
|
|
|
+ style: TextStyle(
|
|
|
+ color:
|
|
|
+ MyColors.cFF4233,
|
|
|
+ fontSize: 14),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ GestureDetector(
|
|
|
+ child: Text(
|
|
|
+ '确定',
|
|
|
+ style: TextStyle(
|
|
|
+ color: MyColors.cFF4233,
|
|
|
+ fontSize: 16),
|
|
|
+ ),
|
|
|
+ onTap: () {
|
|
|
+ if (_address == null) {
|
|
|
+ province = '北京市';
|
|
|
+ city = '北京市';
|
|
|
+ setState(() {});
|
|
|
+ _reController
|
|
|
+ .requestRefresh();
|
|
|
+ Navigator.pop(context);
|
|
|
+ } else {
|
|
|
+ province = _address
|
|
|
+ .currentProvince
|
|
|
+ .province;
|
|
|
+ city = _address
|
|
|
+ .currentCity.city;
|
|
|
+ setState(() {});
|
|
|
+ _reController
|
|
|
+ .requestRefresh();
|
|
|
+ Navigator.pop(context);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ behavior:
|
|
|
+ HitTestBehavior.translucent,
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ mainAxisAlignment:
|
|
|
+ MainAxisAlignment.spaceBetween,
|
|
|
+ ),
|
|
|
),
|
|
|
- visible: pageIndex == 0,
|
|
|
- ),
|
|
|
- ],
|
|
|
- ),
|
|
|
- ),
|
|
|
- ),
|
|
|
- Container(
|
|
|
- width: 40,
|
|
|
- ),
|
|
|
- GestureDetector(
|
|
|
- onTap: () {
|
|
|
- setState(() {
|
|
|
- pageIndex = 1;
|
|
|
- _reController.requestRefresh();
|
|
|
- });
|
|
|
- },
|
|
|
- behavior: HitTestBehavior.translucent,
|
|
|
- child: Container(
|
|
|
- height: 28,
|
|
|
- width: 60,
|
|
|
- alignment: Alignment.center,
|
|
|
- child: Column(
|
|
|
- children: [
|
|
|
- Text(
|
|
|
- '商品',
|
|
|
- style: TextStyle(
|
|
|
- color: pageIndex == 1
|
|
|
- ? MyColors.cFF4233
|
|
|
- : MyColors.c333333,
|
|
|
- fontSize: 16,
|
|
|
- fontWeight: FontWeight.bold),
|
|
|
- ),
|
|
|
- Visibility(
|
|
|
- child: Container(
|
|
|
- width: 32,
|
|
|
- height: 2,
|
|
|
- decoration: BoxDecoration(
|
|
|
- color: MyColors.cFF4233,
|
|
|
- borderRadius:
|
|
|
- BorderRadius.circular(1)),
|
|
|
+ Container(
|
|
|
+ height: 250.0,
|
|
|
+ child: AddressPicker(
|
|
|
+ style: TextStyle(
|
|
|
+ color: Colors.black,
|
|
|
+ fontSize: 17),
|
|
|
+ mode: AddressPickerMode
|
|
|
+ .provinceAndCity,
|
|
|
+ onSelectedAddressChanged:
|
|
|
+ (address) {
|
|
|
+ _address = address;
|
|
|
+ },
|
|
|
+ ),
|
|
|
),
|
|
|
- visible: pageIndex == 1,
|
|
|
- ),
|
|
|
- ],
|
|
|
+ ],
|
|
|
+ ),
|
|
|
),
|
|
|
),
|
|
|
+ );
|
|
|
+ },
|
|
|
+ behavior: HitTestBehavior.translucent,
|
|
|
+ child: Container(
|
|
|
+ padding: EdgeInsets.only(left: 11, right: 14),
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ boxShadow: [
|
|
|
+ BoxShadow(
|
|
|
+ color: MyColors.c7FE1E1E1,
|
|
|
+ blurRadius: 5.0,
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ color: Colors.white,
|
|
|
+ borderRadius: BorderRadius.circular(20)),
|
|
|
+ child: Row(
|
|
|
+ children: [
|
|
|
+ Icon(
|
|
|
+ Icons.location_on_rounded,
|
|
|
+ color: MyColors.c333333,
|
|
|
+ size: 20,
|
|
|
+ ),
|
|
|
+ Text(
|
|
|
+ province == null
|
|
|
+ ? MyCookie().location != null
|
|
|
+ ? MyCookie().location.city
|
|
|
+ : '成都市'
|
|
|
+ : city,
|
|
|
+ style: TextStyle(
|
|
|
+ color: MyColors.c333333,
|
|
|
+ fontSize: 12,
|
|
|
+ fontWeight: FontWeight.bold),
|
|
|
+ ),
|
|
|
+ ],
|
|
|
),
|
|
|
- ],
|
|
|
- mainAxisAlignment: MainAxisAlignment.center,
|
|
|
+ height: 40,
|
|
|
+ alignment: Alignment.center,
|
|
|
+ ),
|
|
|
),
|
|
|
+ alignment: Alignment.center,
|
|
|
),
|
|
|
),
|
|
|
Container(
|
|
|
@@ -594,6 +800,10 @@ class _HomePageState extends State<HomePage>
|
|
|
}
|
|
|
|
|
|
queryAd() {
|
|
|
+ int count = 2;
|
|
|
+ if (container.length == 0) {
|
|
|
+ count = 20;
|
|
|
+ }
|
|
|
MyDio().query({
|
|
|
"key": "ad",
|
|
|
"filters": {
|
|
|
@@ -601,7 +811,7 @@ class _HomePageState extends State<HomePage>
|
|
|
},
|
|
|
"dims": adDims,
|
|
|
"order_by": ["id,desc", "no,desc"],
|
|
|
- "paging": [page, 2]
|
|
|
+ "paging": [page, count]
|
|
|
}, (response, hasError) {
|
|
|
if (!hasError) {
|
|
|
AdBeanEntity entity =
|
|
|
@@ -638,6 +848,18 @@ class _HomePageState extends State<HomePage>
|
|
|
if (_description.text.isNotEmpty) {
|
|
|
conditions.add('name LIKE ${_description.text.toString()}');
|
|
|
}
|
|
|
+ if (MyCookie().location == null && province == null) {
|
|
|
+ conditions.add('province == 四川省');
|
|
|
+ conditions.add('city == 成都市');
|
|
|
+ } else {
|
|
|
+ if (province != null) {
|
|
|
+ conditions.add('province == $province');
|
|
|
+ conditions.add('city == $city');
|
|
|
+ } else if (MyCookie().location != null) {
|
|
|
+ conditions.add('province == ${MyCookie().location.province}');
|
|
|
+ conditions.add('city == ${MyCookie().location.city}');
|
|
|
+ }
|
|
|
+ }
|
|
|
MyDio().query({
|
|
|
"key": "shop",
|
|
|
"filters": {"conditions": conditions},
|