Skip to content

Commit

Permalink
UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Li committed Aug 5, 2019
1 parent 8bd7791 commit 4234668
Show file tree
Hide file tree
Showing 7 changed files with 304 additions and 157 deletions.
3 changes: 3 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: Colors.white,
),
initialRoute: '/',
onGenerateRoute: onGenerateRoute,
);
Expand Down
176 changes: 159 additions & 17 deletions lib/pages/category_page/category_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:scroll_to_index/scroll_to_index.dart';
import '../../utils/color.dart';

class CategoryPage extends StatefulWidget {
Expand All @@ -8,32 +9,173 @@ class CategoryPage extends StatefulWidget {
}

class _CategoryPageState extends State<CategoryPage> {
int _count = 0;
ScrollController _scrollController = ScrollController();
AutoScrollController _controller = AutoScrollController();
List<dynamic> _categorys = [
{'name': '美妆', 'index': 0},
{'name': '个护', 'index': 1},
{'name': '女装', 'index': 2},
{'name': '男装', 'index': 3},
{'name': '箱包', 'index': 4},
{'name': '内衣配饰', 'index': 5},
{'name': '鞋靴', 'index': 6},
{'name': '家纺', 'index': 7},
{'name': '眼镜', 'index': 8},
{'name': '电器', 'index': 9},
{'name': '数码', 'index': 10},
{'name': '餐厨', 'index': 11},
{'name': '运动', 'index': 12},
{'name': '母婴', 'index': 13},
{'name': '家装', 'index': 14},
{'name': '家具', 'index': 15},
{'name': '饮食', 'index': 16},
{'name': '汽配', 'index': 17},
{'name': '正餐', 'index': 18},
{'name': '宠物', 'index': 19},
{'name': '定制', 'index': 20},
{'name': '健康保健', 'index': 21}
];

dynamic _selectedCategory;

@override
void initState() {
super.initState();
setState(() {
_selectedCategory = _categorys[0];
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: ColorUtil.getColor('primary'),
title: Text('Category'),
elevation: 0.0,
titleSpacing: 12.0,
title: _hearderBar,
),
body: Center(
child: Column(
children: <Widget>[
Container(
child: Text('${this._count}'),
body: Row(
children: <Widget>[
Container(
width: 100.0,
child: ListView(
physics: ClampingScrollPhysics(),
controller: _scrollController,
children: _leftListViewItems(),
),
RaisedButton(
child: Text('count++'),
onPressed: () {
setState(() {
this._count++;
});
},
),
Expanded(
child: ListView(
controller: _controller,
children: _categorys.map<Widget>((f) {
return AutoScrollTag(
key: ValueKey(f['index']),
controller: _controller,
index: f['index'],
child: Container(
height: 150.0,
child: Text(f['name']),
),
);
}).toList(),
),
],
),
),
],
),
);
}

_leftAnimateToIndex(int index) {
setState(() {
_selectedCategory = _categorys[index];
});
_scrollController.animateTo(index * 60.0,
duration: Duration(milliseconds: 400), curve: Curves.ease);
}

_rightAnimateToIndex(f) {
setState(() {
_selectedCategory = f;
});
_controller.scrollToIndex(f['index'],
duration: Duration(milliseconds: 200),
preferPosition: AutoScrollPosition.begin);
}

Widget _hearderBar = GestureDetector(
onTap: () {},
child: Container(
padding: EdgeInsets.fromLTRB(8.0, 6.0, 8.0, 6.0),
decoration: BoxDecoration(
color: Colors.grey[100],
),
child: Row(
children: <Widget>[
Container(
child: Icon(
Icons.search,
color: Colors.grey[400],
),
),
SizedBox(width: 5.0),
Expanded(
child: Text(
'请输入您想要的商品',
style: TextStyle(
color: Colors.grey[400],
fontSize: 14.0,
fontWeight: FontWeight.w400,
),
),
),
],
),
),
);

List<Widget> _leftListViewItems() {
return _categorys.map((f) {
return GestureDetector(
child: Container(
color: f['index'] == _selectedCategory['index']
? Colors.white
: Colors.transparent,
alignment: Alignment.center,
height: 60.0,
child: Container(
alignment: Alignment.center,
width: 100.0,
height: 25.0,
decoration: BoxDecoration(
border: Border(
left: BorderSide(
color: f['index'] == _selectedCategory['index']
? ColorUtil.getColor('primary')
: Colors.transparent,
width: 4.0,
style: BorderStyle.solid,
),
),
),
child: Text(
f['name'],
style: TextStyle(
color: f['index'] == _selectedCategory['index']
? ColorUtil.getColor('primary')
: null,
fontSize:
f['index'] == _selectedCategory['index'] ? 16.0 : null,
fontWeight: f['index'] == _selectedCategory['index']
? FontWeight.w600
: null,
),
),
),
),
onTap: () {
_rightAnimateToIndex(f);
},
);
}).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ class _BeautyMakeupTabState extends State<BeautyMakeupTab>
@override
void initState() {
super.initState();
_loadProduct();
_loadProduct();
_scrollController.addListener(() async {
if (isLoading) {
if (isLoading || _productList.length > 100) {
return;
}
double pixels = _scrollController.position.maxScrollExtent -
Expand All @@ -87,7 +87,7 @@ _loadProduct();
setState(() {
isLoading = true;
});
await Future.delayed(Duration(milliseconds: 1500), () {
await Future.delayed(Duration(milliseconds: 1000), () {
_loadProduct();
});
}
Expand Down Expand Up @@ -225,8 +225,10 @@ _loadProduct();
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: !isLoading
? <Widget>[]
children: _productList.length > 100
? <Widget>[
Text(''),
]
: <Widget>[
CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(
Expand Down
90 changes: 45 additions & 45 deletions lib/pages/home_page/category_tabs/recommend_tab/recommend_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class _RecommendTabState extends State<RecommendTab>
super.initState();
_loadProduct();
_scrollController.addListener(() async {
if (isLoading) {
if (isLoading || _productList.length > 100) {
return;
}
double pixels = _scrollController.position.maxScrollExtent -
Expand All @@ -34,7 +34,7 @@ class _RecommendTabState extends State<RecommendTab>
setState(() {
isLoading = true;
});
await Future.delayed(Duration(milliseconds: 1500), () {
await Future.delayed(Duration(milliseconds: 1000), () {
_loadProduct();
});
}
Expand All @@ -60,7 +60,7 @@ class _RecommendTabState extends State<RecommendTab>
[
HomeGuaranteeBar(),
SizedBox(height: 10.0),
_titleline(),
_titleline,
Container(
color: ColorUtil.getColor('bg'),
child: Wrap(
Expand All @@ -79,8 +79,10 @@ class _RecommendTabState extends State<RecommendTab>
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: !isLoading
? <Widget>[]
children: _productList.length > 100
? <Widget>[
Text(''),
]
: <Widget>[
CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(
Expand Down Expand Up @@ -109,47 +111,45 @@ class _RecommendTabState extends State<RecommendTab>
});
}

Widget _titleline() {
return Container(
padding: EdgeInsets.all(10.0),
color: Colors.white,
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.only(bottom: 3.0),
child: Text(
'热销 · 好评',
),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
width: 0.5,
color: ColorUtil.getColor('primary54'),
),
Widget _titleline = Container(
padding: EdgeInsets.all(10.0),
color: Colors.white,
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.only(bottom: 3.0),
child: Text(
'热销 · 好评',
),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
width: 0.5,
color: ColorUtil.getColor('primary54'),
),
),
)
],
),
Row(
children: <Widget>[
SizedBox(height: 5.0),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'用户购买热度实时推荐',
style: TextStyle(color: ColorUtil.getColor('golden')),
),
],
)
],
),
);
}
)
],
),
Row(
children: <Widget>[
SizedBox(height: 5.0),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'用户购买热度实时推荐',
style: TextStyle(color: ColorUtil.getColor('golden')),
),
],
)
],
),
);
}
Loading

0 comments on commit 4234668

Please sign in to comment.