|
|
|
import 'package:dio/dio.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
|
|
import 'package:flutter_swiper/flutter_swiper.dart';
|
|
|
|
import 'package:huixiang/generated/l10n.dart';
|
|
|
|
import 'package:huixiang/home/home_view/home_banner.dart';
|
|
|
|
import 'package:huixiang/home/home_view/home_integral_store.dart';
|
|
|
|
import 'package:huixiang/home/home_view/sign_view.dart';
|
|
|
|
import 'package:huixiang/main.dart';
|
|
|
|
import 'package:huixiang/retrofit/data/article.dart';
|
|
|
|
import 'package:huixiang/retrofit/data/banner.dart';
|
|
|
|
import 'package:huixiang/retrofit/data/base_data.dart';
|
|
|
|
import 'package:huixiang/retrofit/data/brand.dart';
|
|
|
|
import 'package:huixiang/retrofit/data/founder.dart';
|
|
|
|
import 'package:huixiang/retrofit/data/goods.dart';
|
|
|
|
import 'package:huixiang/retrofit/data/page.dart';
|
|
|
|
import 'package:huixiang/retrofit/retrofit_api.dart';
|
|
|
|
import 'package:huixiang/utils/event_type.dart';
|
|
|
|
import 'package:huixiang/utils/flutter_utils.dart';
|
|
|
|
import 'package:huixiang/utils/font_weight.dart';
|
|
|
|
import 'package:huixiang/view_widget/border_text.dart';
|
|
|
|
import 'package:huixiang/view_widget/classic_header.dart';
|
|
|
|
import 'package:huixiang/view_widget/custom_image.dart';
|
|
|
|
import 'package:huixiang/view_widget/hot_item.dart';
|
|
|
|
import 'package:huixiang/view_widget/item_title.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:huixiang/view_widget/login_tips.dart';
|
|
|
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
import 'home_view/brand_view.dart';
|
|
|
|
import 'home_view/founder_store.dart';
|
|
|
|
import 'home_view/hot_article.dart';
|
|
|
|
|
|
|
|
class HomePage extends StatefulWidget {
|
|
|
|
final GestureTapCallback callback;
|
|
|
|
|
|
|
|
HomePage(this.callback);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return _HomePage(callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _HomePage extends State<HomePage> with AutomaticKeepAliveClientMixin {
|
|
|
|
ApiService apiService;
|
|
|
|
final GestureTapCallback callback;
|
|
|
|
|
|
|
|
_HomePage(this.callback);
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
eventBus.on<EventType>().listen((event) {
|
|
|
|
if (event.type < 3) {
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
SwiperController controller = SwiperController();
|
|
|
|
|
|
|
|
List<BannerData> bannerData = [];
|
|
|
|
List<Brand> brandData = [];
|
|
|
|
List<Article> articles = [];
|
|
|
|
List<Goods> gooods = [];
|
|
|
|
Founder founder;
|
|
|
|
|
|
|
|
queryHome() async {
|
|
|
|
EasyLoading.show(status: S.of(context).zhengzaijiazai);
|
|
|
|
|
|
|
|
final SharedPreferences value = await SharedPreferences.getInstance();
|
|
|
|
apiService = ApiService(Dio(),
|
|
|
|
context: context, token: value.getString('token'), showLoading: false);
|
|
|
|
|
|
|
|
BaseData brand = await apiService.queryHomeBrand().catchError((onError) {
|
|
|
|
refreshController.refreshFailed();
|
|
|
|
});
|
|
|
|
if (brand != null && brand.isSuccess) {
|
|
|
|
brandData.clear();
|
|
|
|
brandData.addAll((brand.data["brandList"] as List<dynamic>)
|
|
|
|
.map((e) => Brand.fromJson(e))
|
|
|
|
.toList());
|
|
|
|
founder = Founder.fromJson(brand.data["founder"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseData<PageInfo<Article>> article = await apiService.queryArticle({
|
|
|
|
"pageNum": 1,
|
|
|
|
"pageSize": 3,
|
|
|
|
"searchKey": "",
|
|
|
|
"state": 1,
|
|
|
|
"type": 2
|
|
|
|
}).catchError((onError) {
|
|
|
|
refreshController.refreshFailed();
|
|
|
|
});
|
|
|
|
articles.clear();
|
|
|
|
if (article != null && article.isSuccess) {
|
|
|
|
articles.addAll(article.data.list);
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseData<PageInfo<Goods>> goodsData = await apiService.creditGoods({
|
|
|
|
"orderDesc": true,
|
|
|
|
"orderType": 1,
|
|
|
|
"pageNum": 1,
|
|
|
|
"pageSize": 10,
|
|
|
|
"state": 1
|
|
|
|
}).catchError((onError) {
|
|
|
|
refreshController.refreshFailed();
|
|
|
|
});
|
|
|
|
if (goodsData != null && goodsData.isSuccess) {
|
|
|
|
gooods.clear();
|
|
|
|
gooods.addAll(goodsData.data.list);
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseData<PageInfo<BannerData>> baseData = await apiService.queryBanner({
|
|
|
|
"model": {"type": "HOME_PAGE"},
|
|
|
|
}).catchError((onError) {
|
|
|
|
refreshController.refreshFailed();
|
|
|
|
});
|
|
|
|
if (baseData != null && baseData.isSuccess) {
|
|
|
|
bannerData.clear();
|
|
|
|
bannerData.addAll(baseData.data.records);
|
|
|
|
refreshController.refreshCompleted();
|
|
|
|
if (bannerData.length > 0) controller.move(0, animation: false);
|
|
|
|
} else {
|
|
|
|
refreshController.refreshFailed();
|
|
|
|
}
|
|
|
|
EasyLoading.dismiss();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
super.dispose();
|
|
|
|
refreshController.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
final RefreshController refreshController = RefreshController();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
super.build(context);
|
|
|
|
return Container(
|
|
|
|
child: SmartRefresher(
|
|
|
|
controller: refreshController,
|
|
|
|
enablePullDown: true,
|
|
|
|
enablePullUp: false,
|
|
|
|
header: MyHeader(),
|
|
|
|
physics: BouncingScrollPhysics(),
|
|
|
|
onRefresh: () {
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
physics: NeverScrollableScrollPhysics(),
|
|
|
|
child: FutureBuilder(
|
|
|
|
future: queryHome(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
///banner
|
|
|
|
HomeBanner(bannerData, controller),
|
|
|
|
///签到
|
|
|
|
SignView(),
|
|
|
|
///热门文章
|
|
|
|
HotArticle(articles),
|
|
|
|
///创始人故事
|
|
|
|
FounderStore(founder),
|
|
|
|
///品牌介绍
|
|
|
|
BrandView(brandData),
|
|
|
|
///积分商城
|
|
|
|
HomeIntegralStore(gooods, callback),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool get wantKeepAlive => true;
|
|
|
|
}
|