|
|
|
import 'package:dio/dio.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
|
|
import 'package:huixiang/generated/l10n.dart';
|
|
|
|
import 'package:huixiang/retrofit/data/base_data.dart';
|
|
|
|
import 'package:huixiang/retrofit/data/store.dart';
|
|
|
|
import 'package:huixiang/retrofit/retrofit_api.dart';
|
|
|
|
import 'package:huixiang/view_widget/icon_text.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
class StoreSelectorPage extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return _StoreSelectorPage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _StoreSelectorPage extends State<StoreSelectorPage> {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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: [
|
|
|
|
Expanded(
|
|
|
|
child: ListView.builder(
|
|
|
|
itemCount: storeList != null ? storeList.length : 0,
|
|
|
|
physics: BouncingScrollPhysics(),
|
|
|
|
itemBuilder: (context, position) {
|
|
|
|
return GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
setState(() {
|
|
|
|
groupValue = position;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: buildStoreItem(storeList[position], position),
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
InkWell(
|
|
|
|
onTap: () {
|
|
|
|
if (groupValue == null || groupValue == "") {
|
|
|
|
Fluttertoast.showToast(msg: "请选择一个门店");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Store store = storeList[groupValue];
|
|
|
|
Navigator.of(context).pop({
|
|
|
|
"id":store.id,
|
|
|
|
"address":store.address,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
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),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget buildStoreItem(Store store, position) {
|
|
|
|
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(
|
|
|
|
store.storeName,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: Color(0xFF353535),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 12,
|
|
|
|
),
|
|
|
|
IconText(
|
|
|
|
store.address,
|
|
|
|
isMax: true,
|
|
|
|
textStyle: TextStyle(color: Color(0xFF353535), fontSize: 14),
|
|
|
|
leftIcon: Icons.location_on,
|
|
|
|
iconColor: Color(0xFF32A060),
|
|
|
|
iconSize: 16,
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 4,
|
|
|
|
),
|
|
|
|
IconText(
|
|
|
|
"${store.openStartTime}-${store.openEndTime}",
|
|
|
|
textStyle: TextStyle(color: Color(0xFF353535), fontSize: 14),
|
|
|
|
leftIcon: Icons.access_time,
|
|
|
|
iconColor: Color(0xFF32A060),
|
|
|
|
iconSize: 16,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Radio(
|
|
|
|
value: position,
|
|
|
|
groupValue: groupValue,
|
|
|
|
activeColor: Colors.green,
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
groupValue = value;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
int groupValue = 0;
|
|
|
|
}
|