124 lines
3.8 KiB
Dart
124 lines
3.8 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:plan/api/dto/login_dto.dart';
|
||
import 'package:plan/api/endpoints/user_api.dart';
|
||
import 'package:plan/providers/app_store.dart';
|
||
import 'package:plan/utils/debouncer.dart';
|
||
import 'package:provider/provider.dart';
|
||
import 'package:remixicon/remixicon.dart';
|
||
|
||
class ProfileSection extends StatefulWidget {
|
||
final Function(UserInfo) onUpdate;
|
||
|
||
const ProfileSection({super.key, required this.onUpdate});
|
||
|
||
@override
|
||
State<ProfileSection> createState() => _ProfileSectionState();
|
||
}
|
||
|
||
class _ProfileSectionState extends State<ProfileSection> {
|
||
//输入框
|
||
final TextEditingController _inputController = TextEditingController();
|
||
|
||
final List<String> _tips = [
|
||
"Whenever your coach creates a plan for you, they’ll start by looking at this information.",
|
||
"The more details you share, the better your coach can tailor steps that fit your unique situation.",
|
||
"You can also add requests here — for example, ‘I don’t eat cilantro.",
|
||
];
|
||
|
||
//防抖
|
||
Debouncer debouncer = Debouncer(milliseconds: 2000);
|
||
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
AppStore appStore = context.read<AppStore>();
|
||
_inputController.text = appStore.userInfo?.description ?? "";
|
||
}
|
||
|
||
@override
|
||
void dispose() {
|
||
super.dispose();
|
||
debouncer.dispose();
|
||
}
|
||
|
||
///确定编辑画像
|
||
void _onTextChanged(String value) {
|
||
debouncer.run(() async {
|
||
var res = await updateUserInfoApi(description: value);
|
||
widget.onUpdate(res);
|
||
});
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Container(
|
||
margin: EdgeInsets.only(top: 30),
|
||
padding: EdgeInsets.only(top: 30),
|
||
decoration: BoxDecoration(
|
||
border: Border(
|
||
top: BorderSide(
|
||
width: 1,
|
||
color: Theme.of(context).colorScheme.surfaceContainer,
|
||
),
|
||
),
|
||
),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Container(
|
||
margin: EdgeInsets.only(bottom: 20),
|
||
child: Text("About You"),
|
||
),
|
||
Container(
|
||
margin: EdgeInsets.only(bottom: 20),
|
||
child: TextField(
|
||
maxLines: 5,
|
||
maxLength: 500,
|
||
controller: _inputController,
|
||
style: TextStyle(fontSize: 14, letterSpacing: 1),
|
||
onChanged: _onTextChanged,
|
||
decoration: InputDecoration(
|
||
hintText: "I’m 19 and always use a dishwasher. Please don’t follow the hand-wash disassembly steps.",
|
||
enabledBorder: OutlineInputBorder(
|
||
borderSide: BorderSide(color: Colors.grey), // 普通状态
|
||
borderRadius: BorderRadius.circular(8),
|
||
),
|
||
focusedBorder: OutlineInputBorder(
|
||
borderSide: BorderSide(color: Colors.grey), // 获取焦点状态
|
||
borderRadius: BorderRadius.circular(8),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
ListView.separated(
|
||
shrinkWrap: true,
|
||
physics: NeverScrollableScrollPhysics(),
|
||
itemBuilder: (_, index) {
|
||
return Row(
|
||
spacing: 10,
|
||
children: [
|
||
Icon(
|
||
RemixIcons.lightbulb_flash_fill,
|
||
color: Color(0xfff2a529),
|
||
size: 18,
|
||
),
|
||
Expanded(
|
||
child: Text(
|
||
_tips[index],
|
||
style: Theme.of(context).textTheme.labelMedium,
|
||
),
|
||
),
|
||
],
|
||
);
|
||
},
|
||
separatorBuilder: (_, __) {
|
||
return SizedBox(height: 10);
|
||
},
|
||
itemCount: _tips.length,
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|