first commit
This commit is contained in:
1
untitled/lib/views/Home/.pydio
Normal file
1
untitled/lib/views/Home/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
0c5d82c8-0a08-4f49-94e2-57df03cd7df2
|
||||
83
untitled/lib/views/Home/ClassList.dart
Normal file
83
untitled/lib/views/Home/ClassList.dart
Normal file
@@ -0,0 +1,83 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
||||
import 'package:peach/config/_.dart';
|
||||
import 'package:peach/entity/_.dart';
|
||||
import 'package:peach/service/_.dart';
|
||||
import 'package:peach/widget/_.dart';
|
||||
import 'package:flutter_easyrefresh/easy_refresh.dart';
|
||||
import 'package:toast/toast.dart';
|
||||
|
||||
/*
|
||||
* 横向菜单除首页外的布局
|
||||
*/
|
||||
class ClassList extends StatefulWidget {
|
||||
int id;
|
||||
int totalPage = 0;
|
||||
List<ItemList> result = [];
|
||||
|
||||
EasyRefreshController _controller; // EasyRefresh控制器
|
||||
|
||||
ClassList({Key key, @required this.id }) : super(key: key);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _ClassList();
|
||||
}
|
||||
|
||||
class _ClassList extends State<ClassList> with AutomaticKeepAliveClientMixin {
|
||||
|
||||
int page = 1;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
widget._controller = EasyRefreshController();
|
||||
new Future.delayed(Duration(milliseconds: 500), () async {
|
||||
getClassListData();
|
||||
});
|
||||
}
|
||||
|
||||
/// 请求数据,类型是根据ajax生成的数据实体类
|
||||
Future<AgentClassListData> getClassListData() async {
|
||||
AgentClassListData res = await HomeService.GetClassListData(params: {
|
||||
'id': widget.id,
|
||||
'page': page
|
||||
});
|
||||
setState(() {
|
||||
widget.result.addAll(res.list);
|
||||
widget.totalPage = int.parse(res.total);
|
||||
page = int.parse(res.page);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return EasyRefresh(
|
||||
header: BezierCircleHeader(backgroundColor: ColorConfig.ThemeColor),
|
||||
footer: BezierBounceFooter(backgroundColor: ColorConfig.ThemeColor),
|
||||
onRefresh: () async {
|
||||
// widget.page = 0;
|
||||
// widget.result = [];
|
||||
// await getClassListData();
|
||||
},
|
||||
onLoad: () async {
|
||||
page += 1;
|
||||
if (page > widget.totalPage) {
|
||||
Toast.show("没有数据", context, duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM);
|
||||
} else {
|
||||
await getClassListData();
|
||||
widget._controller.finishRefresh();
|
||||
}
|
||||
},
|
||||
child: ItemWidget(
|
||||
data: widget.result,
|
||||
title: '',
|
||||
longPress: () {}
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
}
|
||||
66
untitled/lib/views/Home/Default.dart
Normal file
66
untitled/lib/views/Home/Default.dart
Normal file
@@ -0,0 +1,66 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:peach/config/_.dart';
|
||||
import 'package:peach/entity/_.dart';
|
||||
import 'package:peach/utils/_.dart';
|
||||
import 'package:peach/widget/_.dart';
|
||||
import 'package:peach/service/_.dart';
|
||||
|
||||
/*
|
||||
* 首页的布局
|
||||
*/
|
||||
class DefaultLayout extends StatefulWidget {
|
||||
@override
|
||||
State<StatefulWidget> createState() => _Default();
|
||||
|
||||
}
|
||||
|
||||
class _Default extends State<DefaultLayout> with AutomaticKeepAliveClientMixin<DefaultLayout> {
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
/// 请求数据,被异步数据组件 FutureBuilder 调用
|
||||
Future<Result> GetHomeData() async {
|
||||
return await HomeService.GetHomeData(params: {});
|
||||
}
|
||||
|
||||
/// 首页的列表
|
||||
Widget DeaultPageList(Result result) {
|
||||
var Models = Tool.splitList(result.model.res, 4);
|
||||
return SingleChildScrollView(
|
||||
scrollDirection: Axis.vertical,
|
||||
physics: BouncingScrollPhysics(),
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(height: Screen.setHeight(18),),
|
||||
// SwiperWidget(
|
||||
// autoplayDelay: 4000,
|
||||
// autoplay: false,
|
||||
// child: [
|
||||
// ModelWidget(data: Models[0]),
|
||||
// ModelWidget(data: Models[1]),
|
||||
// ]
|
||||
// ),
|
||||
OldItemWidget(icon: Icons.new_releases_sharp, title: '最新收录', data: result.newest.data),
|
||||
OldItemWidget(icon: Icons.thumb_up_alt,title: '推荐写真', data: result.recommended.data,)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return FutureBuilderWidget<Result>(
|
||||
future: GetHomeData,
|
||||
success: DeaultPageList,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
|
||||
}
|
||||
167
untitled/lib/views/Home/Edit.dart
Normal file
167
untitled/lib/views/Home/Edit.dart
Normal file
@@ -0,0 +1,167 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_modular/flutter_modular.dart';
|
||||
import 'package:toast/toast.dart';
|
||||
import 'package:peach/config/_.dart';
|
||||
import 'package:peach/entity/_.dart';
|
||||
import 'package:peach/service/_.dart';
|
||||
import 'package:peach/utils/_.dart';
|
||||
import 'package:peach/event/_.dart';
|
||||
|
||||
/*
|
||||
* 菜单编辑页面
|
||||
*/
|
||||
class Edit extends StatefulWidget {
|
||||
@override
|
||||
State<StatefulWidget> createState() => _Edit();
|
||||
}
|
||||
|
||||
class _Edit extends State<Edit> {
|
||||
|
||||
// 已选菜单
|
||||
List<Principal> principal = [];
|
||||
// 未选菜单
|
||||
List<Principal> additional = [];
|
||||
bool isEdit = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
GetList();
|
||||
}
|
||||
|
||||
void GetList () {
|
||||
new Future.delayed(Duration(milliseconds: 280),() async {
|
||||
var a = await ClassService.findAll("Principal");
|
||||
var b = await ClassService.findAll("Additional");
|
||||
|
||||
setState(() {
|
||||
principal = a.map((e) => Principal.fromJson(e) ).toList();
|
||||
additional = b.map((e)=> Principal.fromJson(e)).toList();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 已选菜单 被点击的时候
|
||||
principalClick(Principal item) {
|
||||
// 删除原本的数据
|
||||
principal = principal.where((v) => v.id != item.id).toList();
|
||||
|
||||
var isHave = additional.where((v) => v.id == item.id).toList();
|
||||
if (isHave.length == 0) {
|
||||
// 向 未选菜单 添加数据
|
||||
additional.addAll([item]);
|
||||
ClassService.add(tableName: 'Additional', item: item);
|
||||
}
|
||||
|
||||
isEdit = true;
|
||||
setState(() {});
|
||||
ClassService.delete(tableName: 'Principal', item: item);
|
||||
}
|
||||
|
||||
// 未选菜单 被点击的时候
|
||||
additionalClick(Principal item) {
|
||||
// 删除原本的数据
|
||||
additional = additional.where((v) => v.id != item.id).toList();
|
||||
// 向 已选菜单 添加数据
|
||||
principal.addAll([item]);
|
||||
isEdit = true;
|
||||
setState(() {});
|
||||
ClassService.delete(tableName: 'Additional', item: item);
|
||||
ClassService.add(tableName: 'Principal', item: item);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return WillPopScope(
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("分类编辑"),
|
||||
backgroundColor: ColorConfig.ThemeColor,
|
||||
leading: new IconButton(
|
||||
icon: new Icon(Icons.arrow_back),
|
||||
onPressed: () {
|
||||
Config.eventBus.fire(ClassEditEvent(isEdit));
|
||||
Modular.to.pop();
|
||||
},
|
||||
),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
scrollDirection: Axis.vertical,
|
||||
physics: BouncingScrollPhysics(),
|
||||
padding: EdgeInsets.only(top: 15,right: 15,bottom: 0,left: 15),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
margin: EdgeInsets.only(bottom: 20),
|
||||
padding: EdgeInsets.all(8),
|
||||
color: Color(0XFFe1e1e3),
|
||||
width: double.infinity,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text("注意",style: TextStyle(fontSize: 16,fontWeight: FontWeight.w500),),
|
||||
SizedBox(height: Screen.setHeight(10),),
|
||||
Text("1:如果编辑了分类,首页之前的浏览进度将丢失。",style: TextStyle(),),
|
||||
SizedBox(height: Screen.setHeight(5),),
|
||||
Text("2:如果没有编辑分类,那么返回首页,之前的浏览进度都还会在。",style: TextStyle(),),
|
||||
SizedBox(height: Screen.setHeight(5),),
|
||||
Text("3:如果你删除【已选菜单】的所有分类,那么将默认从服务器请求最新菜单",style: TextStyle(),),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(bottom: 20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text("已选菜单",style: TextStyle(fontSize: Screen.setFontSize(16),fontWeight: FontWeight.w400),),
|
||||
SizedBox(height: Screen.setHeight(5),),
|
||||
Wrap(
|
||||
spacing: Screen.setFontSize(13),
|
||||
children: principal.map((e) => RawChip(
|
||||
label: Text(e.title,style: TextStyle(fontSize: 12,color: ColorConfig.WhiteBackColor)),
|
||||
padding: EdgeInsets.all(1),
|
||||
backgroundColor: ColorConfig.ThemeOtherColor,
|
||||
selectedColor: ColorConfig.ThemeColor,
|
||||
checkmarkColor: Colors.white,
|
||||
onPressed: () {
|
||||
principalClick(e);
|
||||
},
|
||||
)).toList(),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(bottom: Screen.setFontSize(20)),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text("未选菜单",style: TextStyle(fontSize: Screen.setFontSize(16),fontWeight: FontWeight.w400),),
|
||||
SizedBox(height: Screen.setHeight(5),),
|
||||
Wrap(
|
||||
spacing: Screen.setFontSize(18),
|
||||
children: additional.map((e) => RawChip(
|
||||
label: Text(e.title,style: TextStyle(fontSize: Screen.setFontSize(12),color: ColorConfig.WhiteBackColor)),
|
||||
padding: EdgeInsets.all(1),
|
||||
backgroundColor: ColorConfig.ThemeOtherColor,
|
||||
selectedColor: ColorConfig.ThemeColor,
|
||||
checkmarkColor: Colors.white,
|
||||
onPressed: () {
|
||||
additionalClick(e);
|
||||
},
|
||||
)).toList(),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
onWillPop: () async {
|
||||
Config.eventBus.fire(ClassEditEvent(isEdit));
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
189
untitled/lib/views/Home/Home.dart
Normal file
189
untitled/lib/views/Home/Home.dart
Normal file
@@ -0,0 +1,189 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_modular/flutter_modular.dart';
|
||||
import 'package:peach/config/_.dart';
|
||||
import 'package:peach/entity/_.dart';
|
||||
import 'package:peach/utils/_.dart';
|
||||
import 'package:peach/service/_.dart';
|
||||
import 'package:peach/event/_.dart';
|
||||
import 'package:peach/views/Home/Default.dart';
|
||||
import 'package:peach/views/Home/ClassList.dart';
|
||||
import 'package:peach/views/Home/Random.dart';
|
||||
|
||||
/*
|
||||
* 首页
|
||||
*/
|
||||
class Home extends StatefulWidget {
|
||||
@override
|
||||
State<StatefulWidget> createState() => _Home();
|
||||
}
|
||||
|
||||
class _Home extends State<Home> with AutomaticKeepAliveClientMixin<Home> {
|
||||
|
||||
/// 保存横向菜单的数据
|
||||
ClassResult Tabs = ClassResult.fromJson({
|
||||
'principal': [], 'additional': []
|
||||
});
|
||||
|
||||
int _currentIndex = 0;
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
|
||||
TabController _tabController;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
/// 请求权限
|
||||
AuthorityApplication.init(context);
|
||||
_GetClassData();
|
||||
_EditOnListen();
|
||||
}
|
||||
|
||||
void _EditOnListen () {
|
||||
Config.eventBus.on<ClassEditEvent>().listen((event){
|
||||
print("事件监听 ClassEditEvent ============== :${event.update}");
|
||||
if (event.update) {
|
||||
print("true");
|
||||
_currentIndex = 0;
|
||||
Tabs = ClassResult.fromJson({ 'principal': [], 'additional': [] });
|
||||
_GetClassData();
|
||||
} else {
|
||||
print("false");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _GetClassData() async {
|
||||
if (Tabs.principal.length == 0) {
|
||||
Tabs = await HomeService.GetClassData(params: {});
|
||||
// 插入首页
|
||||
Tabs.principal.insert(0, Principal.fromJson({ 'id': 0, 'title': '随机展示','page': 0, }));
|
||||
Tabs.principal.insert(0, Principal.fromJson({ 'id': 1, 'title': '首页','page': 0,}));
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
/// 横向滑动分类菜单边上的右侧编辑按钮
|
||||
Widget RightEdit() {
|
||||
return Container(
|
||||
width: Screen.setWidth(50),
|
||||
child: IconButton(
|
||||
iconSize: Screen.setFontSize(20.0),
|
||||
icon: const Icon(Icons.edit, color: ColorConfig.NoActiveColor,),
|
||||
onPressed: () {
|
||||
Modular.to.pushNamed('/edit');
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 横向滑动分类菜单
|
||||
Widget MenuList() {
|
||||
return Expanded(
|
||||
child: TabBar(
|
||||
isScrollable: true,
|
||||
unselectedLabelColor: ColorConfig.NoActiveColor,
|
||||
indicatorColor: ColorConfig.ThemeColor,
|
||||
tabs: Tabs.principal.map((e) => Tab(text: e.title,)).toList(),
|
||||
onTap: (int index) {
|
||||
print("你点击的下标为 ============== :$index");
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 左侧Logo按钮
|
||||
Widget Leading () {
|
||||
return Builder(
|
||||
builder: (BuildContext context) {
|
||||
return IconButton(
|
||||
icon: IconFont.LogoIcon(),
|
||||
onPressed: () {
|
||||
|
||||
}
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 标题的容器
|
||||
Widget TitleWidget() {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
Modular.to.pushNamed("/search");
|
||||
},
|
||||
child: Container(
|
||||
height: Screen.setHeight(30.0),
|
||||
alignment: Alignment.center,
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: ColorConfig.WhiteBackColor,
|
||||
borderRadius: BorderRadius.all(Radius.circular(25.0)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.search, color: Color(0XFF999999), size: 14),
|
||||
SizedBox(width: Screen.setWidth(2.0)),
|
||||
Text("198万张图,有你想要的...", style: TextStyle(color: Color(0xFf999999), fontSize: Screen.setFontSize(13)))
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 返回不同的布局
|
||||
List<Widget> TabView() {
|
||||
return Tabs.principal.map((e) =>
|
||||
e.id == 1
|
||||
? DefaultLayout()
|
||||
: e.id == 0 ? Random() : ClassList(id: e.id,key: GlobalKey(),)
|
||||
).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return DefaultTabController(
|
||||
key: GlobalKey(),
|
||||
length: Tabs.principal.length != 0 ? Tabs.principal.length : 0,
|
||||
initialIndex: _currentIndex,
|
||||
child: Scaffold(
|
||||
appBar: PreferredSize(
|
||||
preferredSize: Size.fromHeight(90.0),
|
||||
child: AppBar(
|
||||
primary: true,
|
||||
titleSpacing: 0.0,
|
||||
backgroundColor: ColorConfig.ThemeColor,
|
||||
leading: Leading(),
|
||||
title: TitleWidget(),
|
||||
elevation: 0,
|
||||
actions: [
|
||||
IconButton(
|
||||
iconSize: 24,
|
||||
icon: Icon(Icons.supervisor_account),
|
||||
onPressed: () {
|
||||
Config.tabController.jumpToPage(3);
|
||||
},
|
||||
)
|
||||
],
|
||||
bottom: PreferredSize(
|
||||
preferredSize: Size.fromHeight(40.0),
|
||||
child: Row(
|
||||
children: [
|
||||
MenuList(),
|
||||
RightEdit()
|
||||
],
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
body: TabBarView(
|
||||
children: TabView()
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
74
untitled/lib/views/Home/Random.dart
Normal file
74
untitled/lib/views/Home/Random.dart
Normal file
@@ -0,0 +1,74 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyrefresh/easy_refresh.dart';
|
||||
import 'package:peach/config/_.dart';
|
||||
import 'package:peach/entity/_.dart';
|
||||
import 'package:peach/service/_.dart';
|
||||
import 'package:peach/widget/_.dart';
|
||||
|
||||
|
||||
/*
|
||||
* 随机展示
|
||||
*/
|
||||
class Random extends StatefulWidget {
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _Random();
|
||||
}
|
||||
|
||||
class _Random extends State<Random> with AutomaticKeepAliveClientMixin{
|
||||
|
||||
AgentClassListData result;
|
||||
List<ItemList> list = [];
|
||||
EasyRefreshController _controller; // EasyRefresh控制器
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
random();
|
||||
}
|
||||
|
||||
Future<AgentClassListData> random() async {
|
||||
result = await HomeService.GetAgentRandom(params: {});
|
||||
setState(() {
|
||||
list.addAll(result.list);
|
||||
});
|
||||
}
|
||||
|
||||
void Refresh() {
|
||||
list = [];
|
||||
setState(() {});
|
||||
random();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return Scaffold(
|
||||
body: EasyRefresh(
|
||||
header: BezierCircleHeader(backgroundColor: ColorConfig.ThemeColor),
|
||||
footer: BezierBounceFooter(backgroundColor: ColorConfig.ThemeColor),
|
||||
onRefresh: () async {
|
||||
Refresh();
|
||||
},
|
||||
onLoad: () async {
|
||||
random();
|
||||
},
|
||||
child: ItemWidget(
|
||||
data: list,
|
||||
title: '',
|
||||
longPress: () {}
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
backgroundColor: ColorConfig.ThemeColor,
|
||||
child: Icon(Icons.refresh,color: ColorConfig.WhiteBackColor,),
|
||||
onPressed: () {
|
||||
Refresh();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
}
|
||||
150
untitled/lib/views/Home/Search.dart
Normal file
150
untitled/lib/views/Home/Search.dart
Normal file
@@ -0,0 +1,150 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:toast/toast.dart';
|
||||
import 'package:peach/config/_.dart';
|
||||
import 'package:peach/service/_.dart';
|
||||
import 'package:peach/utils/_.dart';
|
||||
import 'package:peach/entity/_.dart';
|
||||
import 'package:peach/widget/_.dart';
|
||||
|
||||
class Search extends StatefulWidget {
|
||||
@override
|
||||
State<StatefulWidget> createState() => _Search();
|
||||
}
|
||||
|
||||
class _Search extends State<Search> {
|
||||
|
||||
// 搜索框控制器
|
||||
TextEditingController _controller = TextEditingController();
|
||||
FocusNode _userFocusNode = FocusNode();
|
||||
|
||||
// 搜索建议
|
||||
List<String> proposalList = [
|
||||
'JK制服','医生','豹纹','清纯','空姐','大胸','黑丝','美腿','主播','香车','教室','学生装','老师', '风骚','蜜桃社','秀人网'
|
||||
];
|
||||
|
||||
List<ItemList> result = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_controller.addListener(() {});
|
||||
// 监听输入框是否获得焦点,动态返回页面
|
||||
_userFocusNode.addListener(() {
|
||||
SearchProposal();
|
||||
setState(() => {});
|
||||
});
|
||||
}
|
||||
|
||||
// 顶部搜索输入框
|
||||
Widget SearchItem () {
|
||||
return Container(
|
||||
height: Screen.setHeight(30.0),
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: ColorConfig.WhiteBackColor,
|
||||
borderRadius: BorderRadius.all(Radius.circular(25.0)),
|
||||
),
|
||||
child: TextField(
|
||||
controller: _controller,
|
||||
focusNode: _userFocusNode,
|
||||
autofocus: true,
|
||||
showCursor: true,
|
||||
cursorWidth: 2,
|
||||
style: TextStyle(fontSize: 14),
|
||||
cursorRadius: Radius.circular(10),
|
||||
cursorColor: ColorConfig.ThemeColor,
|
||||
textInputAction: TextInputAction.search,
|
||||
onSubmitted: (String val) {
|
||||
GetSearchData();
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
isDense: true,
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.only(left: 15),
|
||||
hintText: '输入搜索关键字',
|
||||
hintStyle: TextStyle(color: ColorConfig.NoActiveColor,fontSize: 14),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 顶部右侧的搜索按钮
|
||||
Widget SearchButton() {
|
||||
return IconButton(
|
||||
icon: Icon(Icons.search, color: ColorConfig.WhiteBackColor,),
|
||||
onPressed: () {
|
||||
GetSearchData();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// 如果输入框获得了焦点,那么返回搜索建议,否则返回搜索列表
|
||||
Widget SearchProposal() {
|
||||
if (_userFocusNode.hasFocus) {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(15),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text("搜索建议",style: TextStyle(fontWeight: FontWeight.w500,fontSize: Screen.setFontSize(15)),),
|
||||
SizedBox(height: Screen.setHeight(10),),
|
||||
Wrap(
|
||||
children: proposalList.map((e) => InkWell(
|
||||
onTap: () {
|
||||
_controller.text = e;
|
||||
GetSearchData();
|
||||
},
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(bottom: Screen.setFontSize(5),right: Screen.setFontSize(5)),
|
||||
decoration: BoxDecoration(
|
||||
color: ColorConfig.ThemeColor,
|
||||
borderRadius: BorderRadius.all(Radius.circular(25.0)),
|
||||
),
|
||||
padding: EdgeInsets.only(left: Screen.setFontSize(8),right: Screen.setFontSize(8),bottom: Screen.setFontSize(3),top: Screen.setFontSize(2)),
|
||||
child: Text(e, style: TextStyle(color: ColorConfig.WhiteBackColor,fontSize: Screen.setFontSize(12)),),
|
||||
),
|
||||
)).toList(),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}else{
|
||||
return ItemWidget(
|
||||
data: result,
|
||||
title: '',
|
||||
longPress: () {}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果输入框不为空,那么输入框失去焦点并关闭键盘展示搜索列表页面
|
||||
GetSearchData() async {
|
||||
if (_controller.text.length != 0) {
|
||||
_userFocusNode.unfocus();
|
||||
List<ItemList> res = await HomeService.GetSearchData(params: { "keyword": _controller.text });
|
||||
setState(() => result = res);
|
||||
} else {
|
||||
FocusScope.of(context).requestFocus(_userFocusNode);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
titleSpacing: 0.0,
|
||||
title: SearchItem(),
|
||||
elevation: 0,
|
||||
backgroundColor: ColorConfig.ThemeColor,
|
||||
actions: [ SearchButton() ],
|
||||
),
|
||||
body: SearchProposal(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
dispose() {
|
||||
super.dispose();
|
||||
_controller.dispose();
|
||||
_userFocusNode.dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user