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.

198 lines
5.9 KiB

4 years ago
import 'package:dio/dio.dart';
4 years ago
import 'package:flutter/material.dart';
4 years ago
import 'package:fluttertoast/fluttertoast.dart';
4 years ago
import 'package:huixiang/generated/l10n.dart';
4 years ago
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/store.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
4 years ago
import 'package:huixiang/view_widget/icon_text.dart';
4 years ago
import 'package:shared_preferences/shared_preferences.dart';
4 years ago
class StoreSelectorPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _StoreSelectorPage();
}
}
class _StoreSelectorPage extends State<StoreSelectorPage> {
4 years ago
ApiService apiService;
@override
void initState() {
super.initState();
SharedPreferences.getInstance().then((value) => {
apiService = ApiService(Dio(), token: value.getString('token')),
queryStory(),
});
}
List<Store> storeList;
queryStory() async {
BaseData baseData = await apiService.queryStory();
if (baseData.isSuccess) {
storeList = (baseData.data as List<dynamic>)
.map((e) => Store.fromJson(e))
.toList();
setState(() {});
} else {
Fluttertoast.showToast(msg: baseData.msg);
}
}
4 years ago
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
S.of(context).mendianxuanzhe,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
centerTitle: false,
backgroundColor: Color(0xFFFAFAFA),
elevation: 0,
leading: GestureDetector(
onTap: () {
Navigator.of(context).pop();
},
child: Container(
alignment: Alignment.centerRight,
margin: EdgeInsets.only(left: 10),
padding: EdgeInsets.all(6),
child: Icon(
Icons.arrow_back_ios,
color: Colors.black,
size: 24,
),
),
),
titleSpacing: 2,
leadingWidth: 56,
),
body: Container(
margin: EdgeInsets.only(top: 18),
child: Column(
children: [
4 years ago
Expanded(
child: ListView.builder(
itemCount: storeList != null ? storeList.length : 0,
physics: BouncingScrollPhysics(),
itemBuilder: (context, position) {
return GestureDetector(
onTap: () {
setState(() {
groupValue = "${storeList[position].id}";
});
},
child: buildStoreItem(storeList[position]),
);
}),
),
InkWell(
onTap: () {
if(groupValue == null || groupValue == "") {
Fluttertoast.showToast(msg: "请选择一个门店");
return;
}
Navigator.of(context).pop(groupValue);
},
child: Container(
padding: EdgeInsets.only(top: 16, bottom: 16),
decoration: BoxDecoration(
color: Color(0xFF32A060),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4),
topRight: Radius.circular(4))),
alignment: Alignment.center,
child: Text(
S.of(context).queren,
style: TextStyle(
fontSize: 16,
color: Color(0xFFFFFFFF),
fontWeight: FontWeight.bold),
),
4 years ago
),
),
],
),
),
);
}
4 years ago
Widget buildStoreItem(Store store) {
4 years ago
return Container(
margin: EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 8),
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0)
],
borderRadius: BorderRadius.all(Radius.circular(8))),
child: Row(
children: [
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
4 years ago
store.storeName,
4 years ago
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Color(0xFF353535),
),
),
4 years ago
SizedBox(
height: 12,
),
4 years ago
IconText(
4 years ago
store.address,
isMax: true,
textStyle: TextStyle(color: Color(0xFF353535), fontSize: 14),
4 years ago
leftIcon: Icons.location_on,
iconColor: Color(0xFF32A060),
iconSize: 16,
),
4 years ago
SizedBox(
height: 4,
),
4 years ago
IconText(
4 years ago
"${store.openStartTime}-${store.openEndTime}",
textStyle: TextStyle(color: Color(0xFF353535), fontSize: 14),
4 years ago
leftIcon: Icons.access_time,
iconColor: Color(0xFF32A060),
iconSize: 16,
),
],
),
),
Radio(
4 years ago
value: "${store.id}",
4 years ago
groupValue: groupValue,
activeColor: Colors.green,
onChanged: (value) {
setState(() {
groupValue = value;
});
})
],
),
);
}
4 years ago
String groupValue = "";
4 years ago
}