| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489 |
- import 'dart:convert';
- import 'package:bbyyy/beans/tourist_goods_bean_entity.dart';
- import 'package:bbyyy/beans/tourist_public_shop_bean_entity.dart';
- import 'package:bbyyy/https/MyDio.dart';
- import 'package:bbyyy/https/url.dart';
- import 'package:bbyyy/my_tools/event_bus.dart';
- import 'package:bbyyy/my_tools/my_apis.dart';
- import 'package:bbyyy/my_tools/my_colors.dart';
- import 'package:bbyyy/my_tools/my_tools.dart';
- import 'package:bbyyy/my_tools/my_views.dart';
- import 'package:bbyyy/paegs/root_page/root_page_view.dart';
- 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:pull_to_refresh/pull_to_refresh.dart';
- class HomePage1 extends StatefulWidget {
- @override
- _HomePage1State createState() => _HomePage1State();
- }
- class _HomePage1State extends State<HomePage1>
- with AutomaticKeepAliveClientMixin {
- var imgs = ['images/banner1.png', 'images/banner2.png', 'images/banner3.png'];
- int selectedIndex = 0;
- var tabs = ['全部'];
- var types = ['货帮', '货品'];
- List<DropdownMenuItem<String>> sortItems = [];
- int typeIndex = 1;
- ScrollController _controller = ScrollController();
- double maxH;
- double minH = 164;
- double H = 0;
- bool showInput = false;
- TextEditingController _description = TextEditingController();
- FocusNode _descriptionFocus = FocusNode();
- RefreshController _reController = RefreshController(initialRefresh: true);
- int page = 1;
- int pageIndex = 0;
- List<TouristPublicShopBeanData> shops = [];
- List<TouristGoodsBeanData> goods = [];
- @override
- void initState() {
- super.initState();
- EventBus().on('toTop', (arg) {
- _controller.animateTo(0.0,
- duration: Duration(milliseconds: 200), curve: Curves.easeIn);
- });
- _controller.addListener(() {
- setState(() {
- if (_controller.offset == 0) {
- RootPageView().toTop = false;
- EventBus().emit('ChangePage');
- } else {
- RootPageView().toTop = true;
- EventBus().emit('ChangePage');
- }
- H = maxH - _controller.offset;
- if (H < minH) {
- H = minH;
- } else if (H > maxH) {
- H = maxH;
- }
- });
- });
- _descriptionFocus.addListener(() {
- if (_descriptionFocus.hasFocus) {
- } else {
- if (_description.text.isEmpty) {
- showInput = false;
- }
- }
- });
- }
- @override
- void dispose() {
- // TODO: implement dispose
- super.dispose();
- EventBus().off('commodity_category');
- EventBus().off('uploadGoods');
- EventBus().off('toTop');
- }
- @override
- Widget build(BuildContext context) {
- maxH = MediaQuery.of(context).size.width * (520 / 750);
- minH = MediaQuery.of(context).padding.top + 64;
- if (H == 0) {
- H = maxH;
- }
- return GestureDetector(
- onTap: () {
- MyTools().hideKeyboard(context);
- },
- behavior: HitTestBehavior.translucent,
- child: Scaffold(
- body: Column(
- children: [
- Stack(
- children: [
- AnimatedContainer(
- height: H,
- duration: Duration(milliseconds: 200),
- child: Swiper(
- itemBuilder: (BuildContext context, int index) {
- return new Image.asset(
- "${imgs[index]}",
- fit: BoxFit.cover,
- );
- },
- itemCount: 3,
- viewportFraction: 1,
- scale: 1,
- autoplay: true,
- ),
- ),
- SafeArea(
- bottom: false,
- 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,
- ),
- ),
- ),
- SafeArea(
- bottom: false,
- child: Container(
- margin: EdgeInsets.only(top: 18),
- width: double.infinity,
- child: GestureDetector(
- onTap: (){
- EventBus().emit('toLogin');
- },
- child: Container(
- decoration: BoxDecoration(
- color: MyColors.cFF4233,
- borderRadius: BorderRadius.circular(14)),
- height: 28,
- width: 28,
- child: SvgPicture.asset(
- 'images/svg/搜索.svg',
- height: 15,
- width: 15,
- color: Colors.white,
- ),
- alignment: Alignment.center,
- margin: EdgeInsets.only(right: 15),
- ),
- ),
- alignment: Alignment.centerRight,
- ),
- ),
- ],
- ),
- Expanded(
- flex: 1,
- child: SmartRefresher(
- controller: _reController,
- onRefresh: onRefresh,
- onLoading: onLoading,
- enablePullDown: true,
- enablePullUp: true,
- child: body(),
- ),
- )
- ],
- ),
- ),
- );
- }
- @override
- // TODO: implement wantKeepAlive
- bool get wantKeepAlive => true;
- void onRefresh() {
- page = 1;
- touristQueryData();
- }
- void onLoading() {
- page++;
- touristQueryData();
- }
- body() {
- if (pageIndex == 1) {
- return body1();
- } else if (pageIndex == 0) {
- return body2();
- }
- }
- body1() {
- double w = (MediaQuery.of(context).size.width - 28 - 8) / 2;
- if (goods.length == 0) {
- return SingleChildScrollView(child: noData());
- } else {
- return GridView.builder(
- controller: _controller,
- gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
- crossAxisCount: 2,
- childAspectRatio: 164 / 261,
- mainAxisSpacing: 8,
- crossAxisSpacing: 8),
- itemCount: goods.length,
- padding: EdgeInsets.only(left: 14, right: 14, top: 14, bottom: 65),
- itemBuilder: (context, index) {
- return GestureDetector(
- onTap: () {
- EventBus().emit('toLogin');
- },
- behavior: HitTestBehavior.translucent,
- child: Card(
- elevation: 2,
- shadowColor: MyColors.c21333333,
- child: Column(
- children: [
- Padding(
- padding: EdgeInsets.only(left: 6, top: 6, bottom: 3),
- child: Row(
- children: [
- ClipRRect(
- child: MyViews()
- .netImg(imgURL(goods[index].shopPic), 20, 20),
- borderRadius: BorderRadius.all(Radius.circular(10)),
- ),
- Expanded(
- child: Container(
- margin: EdgeInsets.only(right: 5, left: 5),
- child: Text(
- goods[index].shopName,
- style: TextStyle(
- color: MyColors.c999999,
- fontSize: 10,
- ),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- softWrap: true,
- ),
- ),
- ),
- ],
- ),
- ),
- MyViews().netImg(imgURL(goods[index].coverPath), w, w,
- placeholder: 'images/svg/goodsDefImg.svg'),
- Container(
- padding: EdgeInsets.only(right: 6, left: 6, top: 8),
- child: Text(
- '${goods[index].title}\n${goods[index].description}',
- style: TextStyle(color: Colors.black, fontSize: 12),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- softWrap: true,
- ),
- ),
- Container(
- padding: EdgeInsets.only(right: 6, left: 6, top: 7),
- child: Row(
- children: [
- Expanded(
- child: Text(
- '¥${goods[index].price}',
- style: TextStyle(
- color: MyColors.cFF4233, fontSize: 15),
- ),
- ),
- Container(
- child: Text(
- '详情',
- style: TextStyle(
- color: MyColors.cFF4233, fontSize: 12),
- ),
- alignment: Alignment.center,
- padding: EdgeInsets.only(bottom: 2),
- decoration: BoxDecoration(
- border: Border.all(
- color: MyColors.cFF4233, width: 1),
- borderRadius:
- BorderRadius.all(Radius.circular(10))),
- height: 20,
- width: 50,
- )
- ],
- ),
- )
- ],
- crossAxisAlignment: CrossAxisAlignment.start,
- ),
- ),
- );
- });
- }
- }
- body2() {
- if (shops.length == 0) {
- return SingleChildScrollView(child: noData());
- } else {
- return ListView.builder(
- controller: _controller,
- itemBuilder: (BuildContext context, int index) {
- return GestureDetector(
- onTap: () {
- EventBus().emit('toLogin');
- },
- behavior: HitTestBehavior.translucent,
- child: Container(
- margin: EdgeInsets.only(bottom: 5),
- child: Card(
- elevation: 2,
- child: Padding(
- padding: const EdgeInsets.all(10),
- child: Row(
- children: [
- ClipRRect(
- child: MyViews().netImg(
- imgURL(shops[index].picture), 70, 70,
- placeholder: 'images/svg/goodsDefImg.svg'),
- borderRadius: BorderRadius.circular(4),
- ),
- Expanded(
- child: Container(
- height: 70,
- margin: EdgeInsets.only(left: 10),
- child: Column(
- children: [
- MyViews().myText(
- '${shops[index].name}(${shops[index].uid})',
- MyColors.c333333,
- 14),
- Text(
- '货帮介绍:${shops[index].introduction}',
- style: TextStyle(
- color: MyColors.c666666, fontSize: 11),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- softWrap: true,
- ),
- Row(
- children: [
- Icon(
- Icons.location_on_outlined,
- size: 15,
- color: MyColors.c666666,
- ),
- Expanded(
- child: Text(
- '${shops[index].address}',
- style: TextStyle(
- color: MyColors.c666666,
- fontSize: 10),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- softWrap: true,
- ),
- ),
- ],
- ),
- ],
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- crossAxisAlignment: CrossAxisAlignment.start,
- ),
- ),
- )
- ],
- ),
- ),
- ),
- ),
- );
- },
- itemCount: shops.length,
- padding: EdgeInsets.all(16),
- );
- }
- }
- void touristQueryData() {
- MyDio().post(MyApis.getApi('visitHome'), {'type': pageIndex, 'page': page},
- (response, hasError) {
- if (!hasError) {
- if (pageIndex == 0) {
- TouristPublicShopBeanEntity entity = TouristPublicShopBeanEntity.fromJson(json.decode(response.data.toString()));
- if (page == 1) {
- shops.clear();
- }
- shops.addAll(entity.data);
- } else {
- TouristGoodsBeanEntity entity = TouristGoodsBeanEntity.fromJson(json.decode(response.data.toString()));
- if (page == 1) {
- goods.clear();
- }
- goods.addAll(entity.data);
- }
- setState(() {});
- }
- endRe(_reController);
- }, (error) {});
- }
- }
|