You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

555 lines
17 KiB

4 years ago
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
4 years ago
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
4 years ago
import 'package:flutter_html/flutter_html.dart';
4 years ago
import 'package:flutter_html/image_render.dart';
4 years ago
import 'package:flutter_swiper/flutter_swiper.dart';
4 years ago
import 'package:huixiang/generated/l10n.dart';
4 years ago
import 'package:huixiang/main.dart';
4 years ago
import 'package:huixiang/retrofit/data/banner.dart';
4 years ago
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/brand_data.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/utils/MyPainter.dart';
4 years ago
import 'package:huixiang/utils/event_type.dart';
4 years ago
import 'package:huixiang/view_widget/classic_header.dart';
import 'package:huixiang/view_widget/custom_image.dart';
4 years ago
import 'package:flutter_screenutil/flutter_screenutil.dart';
4 years ago
import 'package:huixiang/view_widget/loading_view.dart';
4 years ago
import 'package:huixiang/view_widget/store_title_tab.dart';
4 years ago
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:shared_preferences/shared_preferences.dart';
4 years ago
class BrandPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _BrandPage();
}
}
4 years ago
class _BrandPage extends State<BrandPage>
with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
4 years ago
ScrollController scrollController = ScrollController();
4 years ago
GlobalKey chiliGlobalKey = GlobalKey();
GlobalKey milkTeaGlobalKey = GlobalKey();
GlobalKey breadGlobalKey = GlobalKey();
4 years ago
ApiService apiService;
BrandData brandData;
4 years ago
List<BannerData> bannerData = [];
List<String> brandText = [];
var isShowMore = false;
4 years ago
queryHome() async {
4 years ago
// showCupertinoDialog(
// context: context,
// barrierDismissible: true,
// builder: (context) {
// return LoadingView();
// });
4 years ago
BaseData baseData = await apiService.queryHome().catchError((error) {
refreshController.refreshFailed();
});
4 years ago
BaseData banner = await apiService.queryBanner({
4 years ago
"model": {"type": "BRAND_APP"},
4 years ago
}).catchError((error) {
refreshController.refreshFailed();
});
bannerData.clear();
4 years ago
bannerData.addAll((banner.data["records"] as List<dynamic>)
.map((e) => BannerData.fromJson(e))
.toList());
4 years ago
4 years ago
// if (Navigator.canPop(context)) Navigator.of(context).pop();
4 years ago
if (baseData != null && baseData.isSuccess) {
4 years ago
refreshController.refreshCompleted();
brandData = BrandData.fromJson(baseData.data);
brandText = (brandData.contents as Map<String, dynamic>).keys.toList();
4 years ago
setState(() {});
} else {
refreshController.refreshFailed();
}
}
4 years ago
@override
void initState() {
super.initState();
4 years ago
4 years ago
SharedPreferences.getInstance().then((value) => {
apiService = ApiService(Dio(),
context: context, token: value.getString('token')),
queryHome(),
});
4 years ago
eventBus.on<EventType>().listen((event) {
4 years ago
print("object: BrandPage");
4 years ago
if (event.type < 3) {
setState(() {});
}
;
4 years ago
});
4 years ago
}
4 years ago
RefreshController refreshController = RefreshController();
4 years ago
@override
Widget build(BuildContext context) {
4 years ago
super.build(context);
4 years ago
return Scaffold(
appBar: AppBar(
4 years ago
toolbarHeight: 40.h - MediaQuery.of(context).padding.top,
4 years ago
backgroundColor: Colors.white,
elevation: 0,
),
body: Container(
4 years ago
padding: EdgeInsets.only(bottom: 76.h),
4 years ago
child: Stack(
children: [
Container(
4 years ago
child: SmartRefresher(
controller: refreshController,
enablePullDown: true,
enablePullUp: false,
header: MyHeader(),
4 years ago
physics: ClampingScrollPhysics(),
4 years ago
onRefresh: queryHome,
4 years ago
scrollController: scrollController,
4 years ago
child: Container(
child: SingleChildScrollView(
physics: NeverScrollableScrollPhysics(),
child: Container(
color: Color(0xFFF7F7F7),
margin: EdgeInsets.only(top: 16.h),
4 years ago
child: Column(
children: homeChildItem(),
),
4 years ago
),
4 years ago
),
),
),
),
Positioned(
4 years ago
child: StoreTitleTab(
4 years ago
brandText,
scrollController: scrollController,
chiliGlobalKey: chiliGlobalKey,
milkTeaGlobalKey: milkTeaGlobalKey,
breadGlobalKey: breadGlobalKey,
isScroll: true,
),
4 years ago
top: 0,
),
],
),
),
);
}
4 years ago
List<Widget> homeChildItem() {
4 years ago
var widgets = <Widget>[
banner(),
buildInfo(),
4 years ago
StoreTitleTab(
brandText,
scrollController: scrollController,
chiliGlobalKey: chiliGlobalKey,
milkTeaGlobalKey: milkTeaGlobalKey,
breadGlobalKey: breadGlobalKey,
isScroll: false,
)
4 years ago
];
4 years ago
if (brandData == null) return widgets;
(brandData.contents as Map<String, dynamic>).forEach((key, value) {
widgets.add(Container(
key: key == "百年川椒"
? chiliGlobalKey
4 years ago
: (key == "前进麦味" ? breadGlobalKey : milkTeaGlobalKey),
child: Container(
child: Html(
data: value,
4 years ago
customImageRenders: {
networkSourceMatcher(domains: ["flutter.dev"]):
(context, attributes, element) {
return Image.asset("assets/image/default_1.png");
},
},
4 years ago
),
4 years ago
),
));
});
return widgets;
}
4 years ago
Widget buildInfo() {
return Container(
margin: EdgeInsets.only(bottom: 20, top: 16),
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
4 years ago
color: Colors.black.withAlpha(12),
offset: Offset(0, 2),
blurRadius: 14,
spreadRadius: 0,
)
4 years ago
],
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
4 years ago
crossAxisAlignment: CrossAxisAlignment.start,
children: [
4 years ago
GestureDetector(
onTap: () {
Navigator.of(context).pushNamed('/router/founder_story_page');
},
child: Row(
4 years ago
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
4 years ago
children: [
ClipOval(
child: MImage(
brandData == null ? "" : brandData.originAvatar,
fit: BoxFit.cover,
4 years ago
width: 60.w,
height: 60.h,
4 years ago
errorSrc: "assets/image/default_1.png",
fadeSrc: "assets/image/default_1.png",
),
clipBehavior: Clip.hardEdge,
4 years ago
),
4 years ago
SizedBox(
4 years ago
width: 16.w,
4 years ago
),
Expanded(
4 years ago
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text.rich(
TextSpan(children: [
TextSpan(
text:
4 years ago
brandData == null ? "" : brandData.originator,
4 years ago
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.sp,
color: Colors.black,
),
),
4 years ago
TextSpan(
4 years ago
text: " ${S.of(context).jituanchuangbanren}",
4 years ago
style: TextStyle(
fontSize: 10.sp,
color: Colors.black,
),
4 years ago
),
4 years ago
]),
textDirection: TextDirection.ltr,
),
Text(
brandData == null ? "" : brandData.originDesc,
overflow: isShowMore
? TextOverflow.visible
: TextOverflow.ellipsis,
4 years ago
maxLines: isShowMore ? 10 : 2,
4 years ago
style: TextStyle(
fontSize: 12.sp,
color: Colors.black,
),
4 years ago
),
SizedBox(height: 3.h),
GestureDetector(
onTap: () {
setState(() {
isShowMore = !isShowMore;
});
},
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
4 years ago
crossAxisAlignment: CrossAxisAlignment.center,
4 years ago
mainAxisSize: MainAxisSize.max,
children: [
Text(
4 years ago
S.of(context).gengduo,
style: TextStyle(
4 years ago
fontSize: 12.sp,
color: Colors.black,
),
),
Icon(
(isShowMore != null && !isShowMore)
? Icons.chevron_right
4 years ago
: Icons.keyboard_arrow_up,
4 years ago
color: Colors.black,
size: 18,
4 years ago
),
],
4 years ago
),
),
4 years ago
],
),
4 years ago
),
4 years ago
flex: 1,
4 years ago
),
4 years ago
],
),
4 years ago
),
SizedBox(
height: 40,
),
Text(
4 years ago
brandData == null ? "" : brandData.company,
4 years ago
style: TextStyle(
4 years ago
fontSize: 16.sp,
fontWeight: FontWeight.bold,
color: Colors.black,
),
4 years ago
),
SizedBox(
height: 20,
),
Text(
4 years ago
brandData == null ? "" : brandData.companyDesc,
4 years ago
textAlign: TextAlign.justify,
4 years ago
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF353535),
),
4 years ago
),
SizedBox(
height: 40,
),
Text(
4 years ago
S.of(context).linian,
4 years ago
style: TextStyle(
4 years ago
fontSize: 16.sp,
fontWeight: FontWeight.bold,
color: Colors.black,
),
4 years ago
),
SizedBox(
4 years ago
height: 20,
4 years ago
),
Column(
children: [
//理念板块
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: buildIdea(),
// ),
Row(
children: [
4 years ago
_ideaWidget("友爱", "assets/image/icon_idea_ya.png"),
_ideaWidget("纯净", "assets/image/icon_idea_cj.png"),
_ideaWidget("健康", "assets/image/icon_idea_jk.png"),
],
),
SizedBox(
4 years ago
height: 18,
),
//理念板块
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: buildIdea(),
// ),
Row(
children: [
4 years ago
_ideaWidget("有机", "assets/image/icon_idea_yj.png"),
_ideaWidget("环保", "assets/image/icon_idea_hb.png"),
_ideaWidget("智慧", "assets/image/icon_idea_zh.png"),
],
),
],
4 years ago
),
],
),
);
}
//理念板块
// List<Widget> buildIdea() {
// if (brandData == null) return [];
// var ideas = <Widget>[];
// (brandData.ideals as Map<String, dynamic>).forEach((key, value) {
// ideas.add(idea(key, value));
// });
// return ideas;
// }
Widget _ideaWidget(var text, String img) {
return Expanded(
flex: 1,
child: Stack(
alignment: Alignment.center,
children: [
Container(
4 years ago
width: 63,
height: 63,
4 years ago
child: Stack(
alignment: Alignment.center,
children: [
Align(
child: CircleAvatar(
4 years ago
child: Image.asset(img),
4 years ago
radius: 100,
),
),
4 years ago
Text(
text,
style: TextStyle(
4 years ago
fontSize: 18,
4 years ago
fontWeight: FontWeight.w300,
color: Colors.white),
)
],
),
// CircleAvatar(
// radius: 100,
// backgroundImage: Image.asset(img),
// child: Container(
// alignment: Alignment.center,
// child: Text(
// text,
// style: TextStyle(
// fontSize: 18,
// fontWeight: FontWeight.w300,
// color: Colors.white),
// )),
// ),
),
Container(
4 years ago
width: 73,
height: 73,
child: CustomPaint(
painter: MyPainter(
4 years ago
lineColor: Color(0xff32A060), width: 2, isDividerRound: true),
),
)
],
),
);
4 years ago
}
4 years ago
banner() {
return Container(
child: AspectRatio(
aspectRatio: 2.08,
child: Swiper(
viewportFraction: 0.88,
scale: 0.93,
4 years ago
// loop: true,
// autoplay: true,
// duration: 2500,
4 years ago
pagination: SwiperPagination(
alignment: Alignment.bottomCenter,
builder: DotSwiperPaginationBuilder(
size: 8,
activeSize: 8,
space: 5,
activeColor: Colors.black,
color: Colors.black.withAlpha(76),
),
),
4 years ago
physics: BouncingScrollPhysics(),
4 years ago
itemBuilder: (context, position) {
4 years ago
return MImage(
4 years ago
(bannerData != null && position < bannerData.length)
4 years ago
? bannerData[position].imgUrl
4 years ago
: "",
fit: BoxFit.cover,
radius: BorderRadius.circular(8),
errorSrc: "assets/image/default_2_1.png",
fadeSrc: "assets/image/default_2_1.png",
);
4 years ago
},
4 years ago
itemCount: (bannerData != null && bannerData.length > 0)
4 years ago
? bannerData.length
4 years ago
: 1),
4 years ago
),
);
}
4 years ago
Widget idea(key, value) {
return Expanded(
flex: 1,
child: Stack(
alignment: Alignment.center,
children: [
Container(
4 years ago
width: 63.w,
height: 63.h,
child: CircleAvatar(
radius: 100,
backgroundImage: NetworkImage(value),
child: Container(
alignment: Alignment.center,
child: Text(
key,
style: TextStyle(
4 years ago
fontSize: 16.sp,
fontWeight: FontWeight.w300,
color: Colors.white),
)),
4 years ago
),
),
Container(
4 years ago
width: 73.w,
height: 73.h,
child: CustomPaint(
painter: MyPainter(
4 years ago
lineColor: Color(0xff32A060),
width: 2.w,
isDividerRound: true,
),
),
)
],
),
4 years ago
);
// Stack(
// children: [
// MImage(
// value,
// width: 71,
// height: 71,
// fit: BoxFit.cover,
// errorSrc: "assets/image/default_1.png",
// fadeSrc: "assets/image/default_1.png",
// ),
// Positioned(
// bottom: 0,
// child: Container(
// width: 71,
// decoration: BoxDecoration(
// color: Colors.black.withAlpha(125),
// borderRadius: BorderRadius.only(
// bottomRight: Radius.circular(4),
// bottomLeft: Radius.circular(4),
// ),
// ),
// padding: EdgeInsets.symmetric(vertical: 2),
// alignment: Alignment.center,
// child: Text(
// key,
// style: TextStyle(
// color: Colors.white,
// fontSize: 12.sp,
// ),
// ),
// ),
// )
// ],
// );
4 years ago
}
4 years ago
@override
bool get wantKeepAlive => true;
4 years ago
}