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.
672 lines
21 KiB
672 lines
21 KiB
import 'package:dio/dio.dart'; |
|
import 'package:flutter/cupertino.dart'; |
|
import 'package:flutter/material.dart'; |
|
import 'package:flutter/rendering.dart'; |
|
import 'package:flutter_html/flutter_html.dart'; |
|
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart'; |
|
import 'package:huixiang/generated/l10n.dart'; |
|
import 'package:huixiang/main.dart'; |
|
import 'package:huixiang/retrofit/data/banner.dart'; |
|
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'; |
|
import 'package:huixiang/utils/event_type.dart'; |
|
import 'package:huixiang/view_widget/classic_header.dart'; |
|
import 'package:huixiang/view_widget/custom_image.dart'; |
|
import 'package:huixiang/view_widget/icon_text.dart'; |
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
import 'package:huixiang/view_widget/loading_view.dart'; |
|
import 'package:pull_to_refresh/pull_to_refresh.dart'; |
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
|
|
class BrandPage extends StatefulWidget { |
|
@override |
|
State<StatefulWidget> createState() { |
|
return _BrandPage(); |
|
} |
|
} |
|
|
|
class _BrandPage extends State<BrandPage> |
|
with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin { |
|
ScrollController tabController; |
|
|
|
List<String> images = [ |
|
"assets/image/icon_chili.png", |
|
"assets/image/icon_milk_tea.png", |
|
"assets/image/icon_bread.png", |
|
]; |
|
|
|
GlobalKey chiliGlobalKey = GlobalKey(); |
|
GlobalKey milkTeaGlobalKey = GlobalKey(); |
|
GlobalKey breadGlobalKey = GlobalKey(); |
|
|
|
ApiService apiService; |
|
BrandData brandData; |
|
List<BannerData> bannerData = []; |
|
List<String> brandText = []; |
|
var isShowMore = false; |
|
|
|
queryHome() async { |
|
showCupertinoDialog( |
|
context: context, |
|
barrierDismissible: true, |
|
builder: (context) { |
|
return LoadingView(); |
|
}); |
|
BaseData baseData = await apiService.queryHome().catchError((error) { |
|
refreshController.refreshFailed(); |
|
}); |
|
|
|
BaseData banner = await apiService.queryBanner({ |
|
"model": {"type": "BRAND_APP"}, |
|
}).catchError((error) { |
|
refreshController.refreshFailed(); |
|
}); |
|
bannerData.clear(); |
|
bannerData.addAll((banner.data["records"] as List<dynamic>) |
|
.map((e) => BannerData.fromJson(e)) |
|
.toList()); |
|
|
|
if (Navigator.canPop(context)) Navigator.of(context).pop(); |
|
|
|
if (baseData != null && baseData.isSuccess) { |
|
refreshController.refreshCompleted(); |
|
brandData = BrandData.fromJson(baseData.data); |
|
brandText = (brandData.contents as Map<String, dynamic>).keys.toList(); |
|
setState(() {}); |
|
} else { |
|
refreshController.refreshFailed(); |
|
} |
|
} |
|
|
|
@override |
|
void initState() { |
|
super.initState(); |
|
|
|
SharedPreferences.getInstance().then((value) => { |
|
apiService = ApiService(Dio(), |
|
context: context, token: value.getString('token')), |
|
queryHome(), |
|
}); |
|
|
|
if (tabController == null) tabController = ScrollController(); |
|
tabController.addListener(() { |
|
RenderBox chiliRenderBox = |
|
chiliGlobalKey.currentContext.findRenderObject(); |
|
RenderBox milkTeaRenderBox = |
|
milkTeaGlobalKey.currentContext.findRenderObject(); |
|
RenderBox breadRenderBox = |
|
breadGlobalKey.currentContext.findRenderObject(); |
|
|
|
Offset chiliOffset = chiliRenderBox.localToGlobal(Offset.zero); |
|
Offset milkTeaOffset = milkTeaRenderBox.localToGlobal(Offset.zero); |
|
Offset breadOffset = breadRenderBox.localToGlobal(Offset.zero); |
|
|
|
var top = 96.h; |
|
if (chiliOffset.dy <= top) { |
|
if (!isVisible) { |
|
isVisible = true; |
|
setState(() {}); |
|
} |
|
} else { |
|
var b = isVisible; |
|
isVisible = false; |
|
if (b) setState(() {}); |
|
selectedIndex = -1; |
|
} |
|
if (chiliOffset.dy <= top && breadOffset.dy > top) { |
|
selectedIndex = 0; |
|
if (selectedIndex1 != selectedIndex) { |
|
setState(() { |
|
print("object:$selectedIndex"); |
|
}); |
|
selectedIndex1 = selectedIndex; |
|
} |
|
} else if (breadOffset.dy <= top && milkTeaOffset.dy > top) { |
|
selectedIndex = 1; |
|
if (selectedIndex1 != selectedIndex) { |
|
setState(() { |
|
print("object:$selectedIndex"); |
|
}); |
|
selectedIndex1 = selectedIndex; |
|
} |
|
} else if (milkTeaOffset.dy <= top) { |
|
selectedIndex = 2; |
|
if (selectedIndex1 != selectedIndex) { |
|
setState(() { |
|
print("object:$selectedIndex"); |
|
}); |
|
selectedIndex1 = selectedIndex; |
|
} |
|
} |
|
}); |
|
|
|
eventBus.on<EventType>().listen((event) { |
|
print("object: BrandPage"); |
|
setState(() {}); |
|
}); |
|
} |
|
|
|
int selectedIndex = -1; |
|
int selectedIndex1 = -1; |
|
RefreshController refreshController = RefreshController(); |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
super.build(context); |
|
return Scaffold( |
|
appBar: AppBar( |
|
toolbarHeight: 40.h - MediaQuery.of(context).padding.top, |
|
backgroundColor: Colors.white, |
|
elevation: 0, |
|
), |
|
body: Container( |
|
padding: EdgeInsets.only(bottom: 76.h), |
|
child: Stack( |
|
children: [ |
|
Container( |
|
child: SmartRefresher( |
|
controller: refreshController, |
|
enablePullDown: true, |
|
enablePullUp: false, |
|
header: MyHeader(), |
|
physics: BouncingScrollPhysics(), |
|
onRefresh: queryHome, |
|
scrollController: tabController, |
|
child: Container( |
|
child: SingleChildScrollView( |
|
physics: NeverScrollableScrollPhysics(), |
|
child: Container( |
|
color: Color(0xFFF7F7F7), |
|
margin: EdgeInsets.only(top: 16.h), |
|
child: Column( |
|
children: homeChildItem(), |
|
), |
|
), |
|
), |
|
), |
|
), |
|
), |
|
Positioned( |
|
child: Visibility( |
|
visible: isVisible, |
|
child: Container( |
|
width: MediaQuery.of(context).size.width, |
|
child: Container( |
|
height: 52.h, |
|
color: Colors.white, |
|
padding: EdgeInsets.all(6), |
|
alignment: Alignment.center, |
|
child: Row( |
|
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
children: (brandText == null || brandText.isEmpty) |
|
? [] |
|
: (brandText.map((e) { |
|
return item( |
|
e, |
|
selectedIndex == brandText.indexOf(e), |
|
brandText.indexOf(e)); |
|
}).toList()), |
|
), |
|
), |
|
), |
|
), |
|
top: 0, |
|
), |
|
], |
|
), |
|
), |
|
); |
|
} |
|
|
|
List<Widget> homeChildItem() { |
|
var widgets = <Widget>[banner(), buildInfo(), buildTab()]; |
|
if (brandData == null) return widgets; |
|
(brandData.contents as Map<String, dynamic>).forEach((key, value) { |
|
widgets.add(Container( |
|
key: key == "百年川椒" |
|
? chiliGlobalKey |
|
: (key == "前进麦味" ? breadGlobalKey : milkTeaGlobalKey), |
|
child: Container( |
|
child: Html( |
|
data: value, |
|
), |
|
), |
|
)); |
|
}); |
|
|
|
return widgets; |
|
} |
|
|
|
bool isVisible = false; |
|
|
|
Widget buildTab() { |
|
return Container( |
|
// key: tabGlobalKey, |
|
height: 52.h, |
|
padding: EdgeInsets.all(6), |
|
alignment: Alignment.center, |
|
child: Row( |
|
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
children: (brandText == null || brandText.isEmpty) |
|
? [] |
|
: brandText |
|
.map((e) => item(e, selectedIndex == brandText.indexOf(e), |
|
brandText.indexOf(e))) |
|
.toList(), |
|
), |
|
); |
|
} |
|
|
|
Widget item(text, isSelected, index) { |
|
print("selectedIndex: $selectedIndex"); |
|
return GestureDetector( |
|
onTap: () { |
|
FlexParentData parendData; |
|
if (index == 0) { |
|
parendData = |
|
chiliGlobalKey.currentContext.findRenderObject().parentData; |
|
} else if (index == 2) { |
|
parendData = |
|
milkTeaGlobalKey.currentContext.findRenderObject().parentData; |
|
} else if (index == 1) { |
|
parendData = |
|
breadGlobalKey.currentContext.findRenderObject().parentData; |
|
} |
|
double offset = parendData.offset.dy - 52.h + 20.h; |
|
tabController.animateTo(offset, |
|
duration: Duration(seconds: 1), curve: Curves.ease); |
|
}, |
|
child: tabItem(text, isSelected, index), |
|
); |
|
} |
|
|
|
Widget tabItem(text, isSelected, index) { |
|
if (isSelected) { |
|
return IconText( |
|
text, |
|
isMax: false, |
|
rightImage: images[index], |
|
iconSize: 16, |
|
iconColor: Colors.red, |
|
textStyle: TextStyle( |
|
fontWeight: FontWeight.bold, |
|
fontSize: 16, |
|
color: Color(0xFF353535)), |
|
); |
|
} else { |
|
return IconText( |
|
text, |
|
isMax: false, |
|
textStyle: TextStyle( |
|
fontWeight: FontWeight.bold, |
|
fontSize: 16, |
|
color: Color(0xFF353535)), |
|
); |
|
} |
|
} |
|
|
|
Widget buildInfo() { |
|
return Container( |
|
margin: EdgeInsets.only(bottom: 20, top: 16), |
|
padding: EdgeInsets.all(16), |
|
decoration: BoxDecoration( |
|
color: Colors.white, |
|
boxShadow: [ |
|
BoxShadow( |
|
color: Colors.black.withAlpha(12), |
|
offset: Offset(0, 2), |
|
blurRadius: 14, |
|
spreadRadius: 0, |
|
) |
|
], |
|
), |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
GestureDetector( |
|
onTap: () { |
|
Navigator.of(context).pushNamed('/router/founder_story_page'); |
|
}, |
|
child: Row( |
|
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
ClipOval( |
|
child: MImage( |
|
brandData == null ? "" : brandData.originAvatar, |
|
fit: BoxFit.cover, |
|
width: 60, |
|
height: 60, |
|
errorSrc: "assets/image/default_1.png", |
|
fadeSrc: "assets/image/default_1.png", |
|
), |
|
clipBehavior: Clip.hardEdge, |
|
), |
|
SizedBox( |
|
width: 16, |
|
), |
|
Expanded( |
|
child: Column( |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Text.rich( |
|
TextSpan(children: [ |
|
TextSpan( |
|
text: brandData == null ? "" : brandData.originator, |
|
style: TextStyle( |
|
fontWeight: FontWeight.bold, |
|
fontSize: 14, |
|
color: Colors.black, |
|
), |
|
), |
|
TextSpan( |
|
text: " 集团创办人", |
|
style: TextStyle( |
|
fontSize: 10, |
|
color: Colors.black, |
|
), |
|
), |
|
]), |
|
textDirection: TextDirection.ltr, |
|
), |
|
Text( |
|
"李旭清女士于1993年创建以「地球公民责任」为企业理念,打造一个与环境共存共荣的永续有机产业的台湾回乡有机集团。" |
|
"2018年10月李旭清女士带领20几位台湾核心干部返乡落地武汉,将台湾有机产业成功经验带回湖北家乡," |
|
"将产业规模涵盖有机生态农业、食品加工、健康餐饮、文旅、电商、金融、信息、地产等领域。", |
|
softWrap: true, |
|
overflow: isShowMore?TextOverflow.visible:TextOverflow.ellipsis, |
|
style: TextStyle(fontSize: 12, color: Colors.black), |
|
), |
|
SizedBox(height: 3), |
|
GestureDetector( |
|
onTap: (){ |
|
setState(() { |
|
isShowMore=!isShowMore; |
|
}); |
|
}, |
|
child: Expanded( |
|
child: Row( |
|
mainAxisAlignment: MainAxisAlignment.end, |
|
children: [ |
|
Text( |
|
"更多", |
|
style: TextStyle( |
|
fontSize: 12, color: Colors.black), |
|
), |
|
Icon( |
|
(isShowMore != null && !isShowMore) |
|
? Icons.chevron_right |
|
: Icons.keyboard_arrow_up, |
|
color: Colors.black, |
|
size: 18, |
|
), |
|
], |
|
), |
|
), |
|
), |
|
], |
|
), |
|
flex: 1, |
|
), |
|
], |
|
), |
|
), |
|
SizedBox( |
|
height: 40, |
|
), |
|
Text( |
|
brandData == null ? "" : brandData.company, |
|
style: TextStyle( |
|
fontSize: 16.sp, |
|
fontWeight: FontWeight.bold, |
|
color: Colors.black, |
|
), |
|
), |
|
SizedBox( |
|
height: 20, |
|
), |
|
Text( |
|
brandData == null ? "" : brandData.companyDesc, |
|
textAlign: TextAlign.justify, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
color: Color(0xFF353535), |
|
), |
|
), |
|
SizedBox( |
|
height: 40, |
|
), |
|
Text( |
|
S.of(context).linian, |
|
style: TextStyle( |
|
fontSize: 16.sp, |
|
fontWeight: FontWeight.bold, |
|
color: Colors.black, |
|
), |
|
), |
|
SizedBox( |
|
height: 20, |
|
), |
|
Column( |
|
children: [ |
|
//理念板块 |
|
// Row( |
|
// mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
|
// crossAxisAlignment: CrossAxisAlignment.center, |
|
// children: buildIdea(), |
|
// ), |
|
Row( |
|
children: [ |
|
_ideaWidget("友爱", |
|
"assets/image/icon_idea_ya.png"), |
|
_ideaWidget("纯净", |
|
"assets/image/icon_idea_cj.png"), |
|
_ideaWidget("健康", |
|
"assets/image/icon_idea_jk.png"), |
|
], |
|
), |
|
SizedBox( |
|
height: 18, |
|
), |
|
//理念板块 |
|
// Row( |
|
// mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
|
// crossAxisAlignment: CrossAxisAlignment.center, |
|
// children: buildIdea(), |
|
// ), |
|
Row( |
|
children: [ |
|
_ideaWidget("有机", |
|
"assets/image/icon_idea_yj.png"), |
|
_ideaWidget("环保", |
|
"assets/image/icon_idea_hb.png"), |
|
_ideaWidget("智慧", |
|
"assets/image/icon_idea_zh.png"), |
|
], |
|
), |
|
], |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
//理念板块 |
|
// 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( |
|
width: 63, |
|
height: 63, |
|
child:Stack( |
|
alignment: Alignment.center, |
|
children: [ |
|
Align( |
|
child: CircleAvatar( |
|
child: Image.asset( |
|
img), |
|
radius: 100, |
|
), |
|
), |
|
Text(text,style:TextStyle( |
|
fontSize: 18, |
|
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( |
|
width: 73, |
|
height: 73, |
|
child: CustomPaint( |
|
painter: MyPainter( |
|
lineColor: Color(0xff32A060), width: 2, isDividerRound: true), |
|
), |
|
) |
|
], |
|
), |
|
); |
|
} |
|
|
|
banner() { |
|
return Container( |
|
child: AspectRatio( |
|
aspectRatio: 2.08, |
|
child: Swiper( |
|
viewportFraction: 0.88, |
|
scale: 0.93, |
|
// loop: true, |
|
// autoplay: true, |
|
// duration: 2500, |
|
pagination: SwiperPagination( |
|
alignment: Alignment.bottomCenter, |
|
builder: DotSwiperPaginationBuilder( |
|
size: 8, |
|
activeSize: 8, |
|
space: 5, |
|
activeColor: Colors.black, |
|
color: Colors.black.withAlpha(76), |
|
), |
|
), |
|
physics: BouncingScrollPhysics(), |
|
itemBuilder: (context, position) { |
|
return MImage( |
|
(bannerData != null && position < bannerData.length) |
|
? bannerData[position].imgUrl |
|
: "", |
|
fit: BoxFit.cover, |
|
radius: BorderRadius.circular(8), |
|
errorSrc: "assets/image/default_2_1.png", |
|
fadeSrc: "assets/image/default_2_1.png", |
|
); |
|
}, |
|
itemCount: (bannerData != null && bannerData.length > 0) |
|
? bannerData.length |
|
: 1), |
|
), |
|
); |
|
} |
|
|
|
Widget idea(key, value) { |
|
return Expanded( |
|
flex: 1, |
|
child: Stack( |
|
alignment: Alignment.center, |
|
children: [ |
|
Container( |
|
width: 63, |
|
height: 63, |
|
child: CircleAvatar( |
|
radius: 100, |
|
backgroundImage: NetworkImage(value), |
|
child: Container( |
|
alignment: Alignment.center, |
|
child: Text( |
|
key, |
|
style: TextStyle( |
|
fontSize: 16, |
|
fontWeight: FontWeight.w300, |
|
color: Colors.white), |
|
)), |
|
), |
|
), |
|
Container( |
|
width: 73, |
|
height: 73, |
|
child: CustomPaint( |
|
painter: MyPainter( |
|
lineColor: Color(0xff32A060), width: 2, isDividerRound: true), |
|
), |
|
) |
|
], |
|
), |
|
); |
|
// 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, |
|
// ), |
|
// ), |
|
// ), |
|
// ) |
|
// ], |
|
// ); |
|
} |
|
|
|
@override |
|
bool get wantKeepAlive => true; |
|
}
|
|
|