Browse Source

UI

null_safety
fmk 3 years ago
parent
commit
81b86f8cc7
  1. 12
      ios/Runner.xcodeproj/project.pbxproj
  2. 8
      lib/article/hot_article_item.dart
  3. 72
      lib/home/huixiang_brand_page.dart
  4. 4
      lib/retrofit/data/article.dart
  5. 4
      lib/retrofit/data/brand.dart
  6. 73
      lib/view_widget/hot_item.dart
  7. 151
      lib/view_widget/store_title_tab.dart

12
ios/Runner.xcodeproj/project.pbxproj

@ -874,7 +874,7 @@
CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = NO; CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = NO;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 33; CURRENT_PROJECT_VERSION = 34;
DEVELOPMENT_TEAM = YF3Q8DVP52; DEVELOPMENT_TEAM = YF3Q8DVP52;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
@ -924,7 +924,7 @@
"$(PROJECT_DIR)/baidu", "$(PROJECT_DIR)/baidu",
"$(PROJECT_DIR)/Runner/baidu", "$(PROJECT_DIR)/Runner/baidu",
); );
MARKETING_VERSION = 1.0.33; MARKETING_VERSION = 1.0.34;
ONLY_ACTIVE_ARCH = NO; ONLY_ACTIVE_ARCH = NO;
OTHER_LDFLAGS = ( OTHER_LDFLAGS = (
"$(inherited)", "$(inherited)",
@ -1110,7 +1110,7 @@
CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = NO; CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = NO;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 33; CURRENT_PROJECT_VERSION = 34;
DEVELOPMENT_TEAM = YF3Q8DVP52; DEVELOPMENT_TEAM = YF3Q8DVP52;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
@ -1160,7 +1160,7 @@
"$(PROJECT_DIR)/baidu", "$(PROJECT_DIR)/baidu",
"$(PROJECT_DIR)/Runner/baidu", "$(PROJECT_DIR)/Runner/baidu",
); );
MARKETING_VERSION = 1.0.33; MARKETING_VERSION = 1.0.34;
ONLY_ACTIVE_ARCH = YES; ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = ( OTHER_LDFLAGS = (
"$(inherited)", "$(inherited)",
@ -1239,7 +1239,7 @@
CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = NO; CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = NO;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 33; CURRENT_PROJECT_VERSION = 34;
DEVELOPMENT_TEAM = YF3Q8DVP52; DEVELOPMENT_TEAM = YF3Q8DVP52;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
@ -1289,7 +1289,7 @@
"$(PROJECT_DIR)/baidu", "$(PROJECT_DIR)/baidu",
"$(PROJECT_DIR)/Runner/baidu", "$(PROJECT_DIR)/Runner/baidu",
); );
MARKETING_VERSION = 1.0.33; MARKETING_VERSION = 1.0.34;
ONLY_ACTIVE_ARCH = NO; ONLY_ACTIVE_ARCH = NO;
OTHER_LDFLAGS = ( OTHER_LDFLAGS = (
"$(inherited)", "$(inherited)",

8
lib/article/hot_article_item.dart

@ -111,11 +111,11 @@ class _HotArticlePage extends State<HotArticlePage> {
scrollDirection: Axis.vertical, scrollDirection: Axis.vertical,
itemBuilder: (context, position) { itemBuilder: (context, position) {
return AspectRatio( return AspectRatio(
aspectRatio: 2.47, aspectRatio: position == 0 ? 1.38 : 3.56,
child: Container( child: Container(
height: 130.h, height: position == 0 ? 247.h : 96.h,
margin: EdgeInsets.symmetric(vertical: 8, horizontal: 16), margin: EdgeInsets.symmetric(vertical: 6.h, horizontal: 16.w),
child: HotArticleItem(article: articles[position]), child: HotArticleItem(article: articles[position], isHot: position == 0),
), ),
); );
}, },

72
lib/home/huixiang_brand_page.dart

@ -10,6 +10,7 @@ import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/main.dart'; import 'package:huixiang/main.dart';
import 'package:huixiang/retrofit/data/banner.dart'; import 'package:huixiang/retrofit/data/banner.dart';
import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/brand.dart';
import 'package:huixiang/retrofit/data/brand_data.dart'; import 'package:huixiang/retrofit/data/brand_data.dart';
import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/utils/MyPainter.dart'; import 'package:huixiang/utils/MyPainter.dart';
@ -32,14 +33,13 @@ class _BrandPage extends State<BrandPage>
with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin { with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
ScrollController scrollController = ScrollController(); ScrollController scrollController = ScrollController();
GlobalKey chiliGlobalKey = GlobalKey();
GlobalKey milkTeaGlobalKey = GlobalKey();
GlobalKey breadGlobalKey = GlobalKey();
ApiService apiService; ApiService apiService;
List<Brand> brands = [];
BrandData brandData; BrandData brandData;
List<GlobalKey> globaKeys = [];
List<BannerData> bannerData = []; List<BannerData> bannerData = [];
List<String> brandText = [];
// List<String> brandText = [];
var isShowMore = false; var isShowMore = false;
queryHome() async { queryHome() async {
@ -56,10 +56,29 @@ class _BrandPage extends State<BrandPage>
.map((e) => BannerData.fromJson(e)) .map((e) => BannerData.fromJson(e))
.toList()); .toList());
BaseData brand = await apiService.queryHomeBrand().catchError((onError) {
refreshController.refreshFailed();
}).catchError((onError) {
refreshController.refreshFailed();
});
if (brand != null && brand.isSuccess) {
brands.clear();
globaKeys.clear();
brands.addAll((brand.data["brandList"] as List<dynamic>)
.map((e) => Brand.fromJson(e))
.toList());
brands.forEach((element) {
globaKeys.add(GlobalKey());
});
setState(() {});
} else {
refreshController.refreshFailed();
}
if (baseData != null && baseData.isSuccess) { if (baseData != null && baseData.isSuccess) {
refreshController.refreshCompleted(); refreshController.refreshCompleted();
brandData = BrandData.fromJson(baseData.data); brandData = BrandData.fromJson(baseData.data);
brandText = (brandData.contents as Map<String, dynamic>).keys.toList(); // brandText = (brandData.contents as Map<String, dynamic>).keys.toList();
setState(() {}); setState(() {});
} else { } else {
refreshController.refreshFailed(); refreshController.refreshFailed();
@ -99,7 +118,8 @@ class _BrandPage extends State<BrandPage>
padding: EdgeInsets.only(bottom: 76.h), padding: EdgeInsets.only(bottom: 76.h),
child: Stack( child: Stack(
children: [ children: [
Container( Positioned(
child: Container(
child: SmartRefresher( child: SmartRefresher(
controller: refreshController, controller: refreshController,
enablePullDown: true, enablePullDown: true,
@ -122,16 +142,22 @@ class _BrandPage extends State<BrandPage>
), ),
), ),
), ),
bottom: 0,
top: 0,
left: 0,
right: 0,
),
if (brands != null && brands.length > 0)
Positioned( Positioned(
child: StoreTitleTab( child: StoreTitleTab(
brandText, brands,
scrollController: scrollController, globaKeys,
chiliGlobalKey: chiliGlobalKey, scrollController,
milkTeaGlobalKey: milkTeaGlobalKey,
breadGlobalKey: breadGlobalKey,
isScroll: true, isScroll: true,
), ),
top: 0, top: 0,
left: 0,
right: 0,
), ),
], ],
), ),
@ -144,24 +170,20 @@ class _BrandPage extends State<BrandPage>
banner(), banner(),
buildInfo(), buildInfo(),
StoreTitleTab( StoreTitleTab(
brandText, brands,
scrollController: scrollController, globaKeys,
chiliGlobalKey: chiliGlobalKey, scrollController,
milkTeaGlobalKey: milkTeaGlobalKey,
breadGlobalKey: breadGlobalKey,
isScroll: false, isScroll: false,
) )
]; ];
if (brandData == null) return widgets; if (brands == null) return widgets;
(brandData.contents as Map<String, dynamic>).forEach((key, value) { brands.forEach((value) {
widgets.add(Container( widgets.add(Container(
key: key == "百年川椒" key: globaKeys[brands.indexOf(value)],
? chiliGlobalKey
: (key == "前进麦味" ? breadGlobalKey : milkTeaGlobalKey),
child: Container( child: Container(
color: Colors.white, color: Colors.white,
child: Html( child: Html(
data: value, data: value.content,
customImageRenders: { customImageRenders: {
base64DataUriMatcher(): base64ImageRender(), base64DataUriMatcher(): base64ImageRender(),
assetUriMatcher(): assetImageRender(), assetUriMatcher(): assetImageRender(),
@ -170,10 +192,6 @@ class _BrandPage extends State<BrandPage>
loadingWidget: () { loadingWidget: () {
return Container(); return Container();
}, },
// mapUrl: (url) {
// print("objectUrl: $url");
// return "$url?imageMogr2/format/webp/blur/1x0/quality/75";
// }
), ),
}, },
), ),

4
lib/retrofit/data/article.dart

@ -67,6 +67,10 @@ class Article {
_likes = value; _likes = value;
} }
set viewers(int value) {
_viewers = value;
}
Article({ Article({
String id, String id,
String createTime, String createTime,

4
lib/retrofit/data/brand.dart

@ -12,6 +12,7 @@ class Brand {
String _video; String _video;
String _desc; String _desc;
String _content; String _content;
String _icon;
int _sort; int _sort;
String _storeId; String _storeId;
@ -20,6 +21,7 @@ class Brand {
String get video => _video; String get video => _video;
String get desc => _desc; String get desc => _desc;
String get content => _content; String get content => _content;
String get icon => _icon;
int get sort => _sort; int get sort => _sort;
String get storeId => _storeId; String get storeId => _storeId;
@ -36,6 +38,7 @@ class Brand {
_video = video; _video = video;
_desc = desc; _desc = desc;
_content = content; _content = content;
_icon = icon;
_sort = sort; _sort = sort;
_storeId = storeId; _storeId = storeId;
} }
@ -46,6 +49,7 @@ class Brand {
_video = json["video"]; _video = json["video"];
_desc = json["desc"]; _desc = json["desc"];
_content = json["content"]; _content = json["content"];
_icon = json["icon"];
_sort = json["sort"]; _sort = json["sort"];
_storeId = json["storeId"]; _storeId = json["storeId"];
} }

73
lib/view_widget/hot_item.dart

@ -9,26 +9,41 @@ import 'package:huixiang/view_widget/custom_image.dart';
import 'package:huixiang/view_widget/icon_text.dart'; import 'package:huixiang/view_widget/icon_text.dart';
import 'package:huixiang/view_widget/round_button.dart'; import 'package:huixiang/view_widget/round_button.dart';
class HotArticleItem extends StatelessWidget { class HotArticleItem extends StatefulWidget {
final Article article; final Article article;
final bool isHot; final bool isHot;
HotArticleItem({this.article, this.isHot}); HotArticleItem({this.article, this.isHot});
@override
State<StatefulWidget> createState() {
return _HotArticleItem();
}
}
class _HotArticleItem extends State<HotArticleItem> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Navigator.of(context).pushNamed('/router/store_detail_page', click();
arguments: {"articleId": article.id});
}, },
child: hotItem(context), child: hotItem(context),
); );
} }
click() async {
await Navigator.of(context).pushNamed('/router/store_detail_page',
arguments: {"articleId": widget.article.id});
widget.article.viewers = (widget.article.viewers + 1);
setState(() {});
}
Widget hotItem(BuildContext context) { Widget hotItem(BuildContext context) {
return Container( return Container(
padding: EdgeInsets.all((isHot == null || !isHot) ? 8 : 0), padding: EdgeInsets.all((widget.isHot == null || !widget.isHot) ? 8 : 0),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Colors.white,
boxShadow: [ boxShadow: [
@ -41,18 +56,18 @@ class HotArticleItem extends StatelessWidget {
], ],
borderRadius: BorderRadius.circular(4), borderRadius: BorderRadius.circular(4),
), ),
child: (isHot == null || !isHot) child: (widget.isHot == null || !widget.isHot)
? Row( ? Row(
children: [ children: [
Visibility( Visibility(
visible: article != null && visible: widget.article != null &&
article.coverImg != null && widget.article.coverImg != null &&
article.coverImg != "", widget.article.coverImg != "",
child: Stack( child: Stack(
alignment: Alignment.center, alignment: Alignment.center,
children: [ children: [
MImage( MImage(
article != null ? article.coverImg : "", widget.article != null ? widget.article.coverImg : "",
fit: BoxFit.cover, fit: BoxFit.cover,
radius: BorderRadius.circular(2), radius: BorderRadius.circular(2),
aspectRatio: 1, aspectRatio: 1,
@ -60,9 +75,9 @@ class HotArticleItem extends StatelessWidget {
fadeSrc: "assets/image/default_1.png", fadeSrc: "assets/image/default_1.png",
), ),
Visibility( Visibility(
visible: (article != null && visible: (widget.article != null &&
article.coverImg != "" && widget.article.coverImg != "" &&
article.coverImg.endsWith(".mp4")), widget.article.coverImg.endsWith(".mp4")),
child: Icon( child: Icon(
Icons.play_circle_outline, Icons.play_circle_outline,
size: 24, size: 24,
@ -94,9 +109,9 @@ class HotArticleItem extends StatelessWidget {
Column( Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
(isHot == null || !isHot) (widget.isHot == null || !widget.isHot)
? Text( ? Text(
article != null ? article.mainTitle : "", widget.article != null ? widget.article.mainTitle : "",
maxLines: 1, maxLines: 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: TextStyle( style: TextStyle(
@ -120,7 +135,7 @@ class HotArticleItem extends StatelessWidget {
width: 6.w, width: 6.w,
), ),
Text( Text(
article != null ? article.mainTitle : "", widget.article != null ? widget.article.mainTitle : "",
maxLines: 1, maxLines: 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: TextStyle( style: TextStyle(
@ -135,7 +150,7 @@ class HotArticleItem extends StatelessWidget {
height: 4.h, height: 4.h,
), ),
Text( Text(
article != null ? (article.viceTitle ?? "") : "", widget.article != null ? (widget.article.viceTitle ?? "") : "",
maxLines: AppUtils.textScale(context) > 1.05 ? 1 : 2, maxLines: AppUtils.textScale(context) > 1.05 ? 1 : 2,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: TextStyle( style: TextStyle(
@ -155,8 +170,8 @@ class HotArticleItem extends StatelessWidget {
children: [ children: [
Text( Text(
S.of(context).zuozhe( S.of(context).zuozhe(
(article != null && article.author != null) (widget.article != null && widget.article.author != null)
? article.author.name ? widget.article.author.name
: ""), : ""),
style: TextStyle( style: TextStyle(
fontSize: 10.sp, fontSize: 10.sp,
@ -177,7 +192,7 @@ class HotArticleItem extends StatelessWidget {
height: 16.h, height: 16.h,
), ),
Text( Text(
(article != null) ? "${article.likes}" : "", (widget.article != null) ? "${widget.article.likes}" : "",
style: TextStyle( style: TextStyle(
fontSize: 10.sp, fontSize: 10.sp,
color: Color(0xFFB2B2B2), color: Color(0xFFB2B2B2),
@ -199,7 +214,7 @@ class HotArticleItem extends StatelessWidget {
height: 16.h, height: 16.h,
), ),
Text( Text(
(article != null) ? "${article.viewers}" : "", (widget.article != null) ? "${widget.article.viewers}" : "",
style: TextStyle( style: TextStyle(
fontSize: 10.sp, fontSize: 10.sp,
color: Color(0xFFB2B2B2), color: Color(0xFFB2B2B2),
@ -213,7 +228,7 @@ class HotArticleItem extends StatelessWidget {
flex: 1, flex: 1,
), ),
IconText( IconText(
article != null ? (article.createTime.split(" ")[0]) : "", widget.article != null ? (widget.article.createTime.split(" ")[0]) : "",
textStyle: TextStyle( textStyle: TextStyle(
fontSize: 10.sp, fontSize: 10.sp,
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
@ -233,15 +248,15 @@ class HotArticleItem extends StatelessWidget {
return [ return [
Expanded( Expanded(
child: Visibility( child: Visibility(
visible: article != null && visible: widget.article != null &&
article.coverImg != null && widget.article.coverImg != null &&
article.coverImg != "", widget.article.coverImg != "",
child: Stack( child: Stack(
alignment: Alignment.center, alignment: Alignment.center,
children: [ children: [
Positioned( Positioned(
child: MImage( child: MImage(
article != null ? article.coverImg : "", widget.article != null ? widget.article.coverImg : "",
fit: BoxFit.cover, fit: BoxFit.cover,
radius: BorderRadius.circular(4), radius: BorderRadius.circular(4),
width: MediaQuery.of(context).size.width - 32.w, width: MediaQuery.of(context).size.width - 32.w,
@ -254,9 +269,9 @@ class HotArticleItem extends StatelessWidget {
), ),
Positioned( Positioned(
child: Visibility( child: Visibility(
visible: (article != null && visible: (widget.article != null &&
article.coverImg != "" && widget.article.coverImg != "" &&
article.coverImg.endsWith(".mp4")), widget.article.coverImg.endsWith(".mp4")),
child: Center( child: Center(
child: Icon( child: Icon(
Icons.play_circle_outline, Icons.play_circle_outline,
@ -284,4 +299,6 @@ class HotArticleItem extends StatelessWidget {
), ),
]; ];
} }
} }

151
lib/view_widget/store_title_tab.dart

@ -1,23 +1,22 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/retrofit/data/brand.dart';
import 'package:huixiang/view_widget/icon_text.dart'; import 'package:huixiang/view_widget/icon_text.dart';
class StoreTitleTab extends StatefulWidget { class StoreTitleTab extends StatefulWidget {
final ScrollController scrollController; final ScrollController scrollController;
final List<String> brandText; final List<Brand> brands;
final GlobalKey chiliGlobalKey;
final GlobalKey milkTeaGlobalKey;
final GlobalKey breadGlobalKey;
final List<GlobalKey> globaKeys;
final bool isScroll; final bool isScroll;
StoreTitleTab(this.brandText, StoreTitleTab(this.brands,
{this.scrollController, this.globaKeys,
this.chiliGlobalKey, this.scrollController,
this.milkTeaGlobalKey, {
this.breadGlobalKey, this.isScroll = false}); this.isScroll = false,
});
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() {
@ -30,28 +29,20 @@ class _StoreTitleTab extends State<StoreTitleTab> {
int selectedIndex1 = -1; int selectedIndex1 = -1;
bool isVisible = false; bool isVisible = false;
List<String> images = [
"assets/image/icon_chili.webp",
"assets/image/icon_milk_tea.webp",
"assets/image/icon_bread.webp",
];
@override @override
void initState() { void initState() {
super.initState(); super.initState();
if (widget.scrollController != null) { print("firstOffset: ${widget.globaKeys}");
print("firstOffset: ${widget.brands}");
if (widget.scrollController != null && widget.globaKeys != null && widget.globaKeys.length > 0) {
widget.scrollController?.addListener(() { widget.scrollController?.addListener(() {
RenderBox chiliRenderBox = widget.chiliGlobalKey.currentContext.findRenderObject(); if (widget.globaKeys[0].currentContext == null) return;
RenderBox milkTeaRenderBox = widget.milkTeaGlobalKey.currentContext.findRenderObject(); RenderBox firstRenderBox = widget.globaKeys[0].currentContext.findRenderObject();
RenderBox breadRenderBox = widget.breadGlobalKey.currentContext.findRenderObject(); Offset first = firstRenderBox?.localToGlobal(Offset.zero);
print("firstOffset: ${first.dy}");
Offset chiliOffset = chiliRenderBox?.localToGlobal(Offset.zero);
Offset milkTeaOffset = milkTeaRenderBox?.localToGlobal(Offset.zero);
Offset breadOffset = breadRenderBox?.localToGlobal(Offset.zero);
var top = 96.h; var top = 96.h;
if (chiliOffset.dy <= top) { if (first.dy <= top) {
if (!isVisible) { if (!isVisible) {
isVisible = true; isVisible = true;
setState(() {}); setState(() {});
@ -62,32 +53,66 @@ class _StoreTitleTab extends State<StoreTitleTab> {
if (b) setState(() {}); if (b) setState(() {});
selectedIndex = -1; selectedIndex = -1;
} }
if (chiliOffset.dy <= top && breadOffset.dy > top) {
selectedIndex = 0; widget.globaKeys.forEach((element) {
if (widget.globaKeys.indexOf(element) < (widget.globaKeys.length - 1)) {
if (element.currentContext == null) return;
RenderBox renderBox = element.currentContext.findRenderObject();
Offset offset = renderBox?.localToGlobal(Offset.zero);
RenderBox nextRenderBox = element.currentContext.findRenderObject();
Offset nextOffset = nextRenderBox?.localToGlobal(Offset.zero);
if (offset.dy <= top && nextOffset.dy > top) {
selectedIndex = widget.globaKeys.indexOf(element);
if (selectedIndex1 != selectedIndex) { if (selectedIndex1 != selectedIndex) {
setState(() { setState(() {
print("object:$selectedIndex"); print("object:$selectedIndex");
}); });
selectedIndex1 = selectedIndex; selectedIndex1 = selectedIndex;
} }
} else if (breadOffset.dy <= top && milkTeaOffset.dy > top) { return;
selectedIndex = 1;
if (selectedIndex1 != selectedIndex) {
setState(() {
print("object:$selectedIndex");
});
selectedIndex1 = selectedIndex;
} }
} else if (milkTeaOffset.dy <= top) { } else {
selectedIndex = 2; RenderBox lastRenderBox = element.currentContext.findRenderObject();
Offset lastOffset = lastRenderBox?.localToGlobal(Offset.zero);
if (lastOffset.dy <= top) {
selectedIndex = widget.globaKeys.indexOf(element);
if (selectedIndex1 != selectedIndex) { if (selectedIndex1 != selectedIndex) {
setState(() { setState(() {
print("object:$selectedIndex"); print("object:$selectedIndex");
}); });
selectedIndex1 = selectedIndex; selectedIndex1 = selectedIndex;
} }
return;
}
} }
}); });
// 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;
// }
// }
});
} }
} }
@ -95,21 +120,23 @@ class _StoreTitleTab extends State<StoreTitleTab> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Visibility( return Visibility(
visible: (!widget.isScroll) ? true : isVisible, visible: (!widget.isScroll) ? true : isVisible,
child: Container( child: SingleChildScrollView(
width: MediaQuery.of(context).size.width, physics: BouncingScrollPhysics(),
scrollDirection: Axis.horizontal,
child: Container( child: Container(
height: 52.h, height: 52.h,
constraints: BoxConstraints(minWidth: MediaQuery.of(context).size.width),
color: Colors.white, color: Colors.white,
padding: EdgeInsets.all(6), padding: EdgeInsets.all(6),
alignment: Alignment.center, alignment: Alignment.center,
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: (widget.brandText == null || widget.brandText.isEmpty) children: (widget.brands == null || widget.brands.length == 0)
? [] ? []
: (widget.brandText.map((e) { : (widget.brands.map((e) {
return item(e, selectedIndex == widget.brandText.indexOf(e), return item(e, selectedIndex == widget.brands.indexOf(e),
widget.brandText.indexOf(e)); widget.brands.indexOf(e));
}).toList()), }).toList()),
), ),
), ),
@ -117,53 +144,53 @@ class _StoreTitleTab extends State<StoreTitleTab> {
); );
} }
Widget item(text, isSelected, index) { Widget item(Brand text, isSelected, index) {
print("selectedIndex: $selectedIndex"); print("selectedIndex: $selectedIndex");
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
FlexParentData parendData; FlexParentData parendData = widget.globaKeys[index].currentContext
if (index == 0) {
parendData = widget.chiliGlobalKey.currentContext
.findRenderObject()
.parentData;
} else if (index == 2) {
parendData = widget.milkTeaGlobalKey.currentContext
.findRenderObject()
.parentData;
} else if (index == 1) {
parendData = widget.breadGlobalKey.currentContext
.findRenderObject() .findRenderObject()
.parentData; .parentData;
}
double offset = parendData.offset.dy - 52.h + 20.h; double offset = parendData.offset.dy - 52.h + 20.h;
widget.scrollController.animateTo(offset, widget.scrollController.animateTo(offset,
duration: Duration(seconds: 1), curve: Curves.ease); duration: Duration(seconds: 1), curve: Curves.ease);
}, },
child: Container(
padding: EdgeInsets.symmetric(horizontal: 15.w),
child: tabItem(text, isSelected, index), child: tabItem(text, isSelected, index),
),
); );
} }
Widget tabItem(text, isSelected, index) { // List<String> images = [
// "assets/image/icon_chili.webp",
// "assets/image/icon_milk_tea.webp",
// "assets/image/icon_bread.webp",
// ];
Widget tabItem(Brand text, isSelected, index) {
if (isSelected) { if (isSelected) {
return IconText( return IconText(
text, text.name,
isMax: false, isMax: false,
rightImage: images[index], rightImage: text.icon ?? "assets/image/icon_chili.webp",
iconSize: 16, iconSize: 16,
iconColor: Colors.red, iconColor: Colors.red,
textStyle: TextStyle( textStyle: TextStyle(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 16.sp, fontSize: 16.sp,
color: Color(0xFF353535)), color: Color(0xFF353535),
),
); );
} else { } else {
return IconText( return IconText(
text, text.name,
isMax: false, isMax: false,
textStyle: TextStyle( textStyle: TextStyle(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 16.sp, fontSize: 16.sp,
color: Color(0xFF353535)), color: Color(0xFF353535),
),
); );
} }
} }

Loading…
Cancel
Save