180 lines
5.9 KiB
Dart
180 lines
5.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../../models/watermark.dart';
|
|
|
|
/// 编辑这一张照片的水印内容(地址 / 天气 / 温度 / 备注)
|
|
///
|
|
/// 返回 null 表示用户取消了。时间不在这里改 —— 它总是「现在」,
|
|
/// 让用户手改反而容易把水印弄成假的时间。
|
|
Future<WatermarkData?> showWatermarkContentSheet(
|
|
BuildContext context, {
|
|
required WatermarkData initial,
|
|
}) {
|
|
return showModalBottomSheet<WatermarkData>(
|
|
context: context,
|
|
backgroundColor: Colors.white,
|
|
isScrollControlled: true,
|
|
shape: const RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
|
),
|
|
builder: (_) => _WatermarkContentSheet(initial: initial),
|
|
);
|
|
}
|
|
|
|
class _WatermarkContentSheet extends StatefulWidget {
|
|
const _WatermarkContentSheet({required this.initial});
|
|
|
|
final WatermarkData initial;
|
|
|
|
@override
|
|
State<_WatermarkContentSheet> createState() => _WatermarkContentSheetState();
|
|
}
|
|
|
|
class _WatermarkContentSheetState extends State<_WatermarkContentSheet> {
|
|
late final TextEditingController _address;
|
|
late final TextEditingController _weather;
|
|
late final TextEditingController _temperature;
|
|
late final TextEditingController _remark;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_address = TextEditingController(text: widget.initial.address);
|
|
_weather = TextEditingController(text: widget.initial.weather);
|
|
_temperature = TextEditingController(text: widget.initial.temperature);
|
|
_remark = TextEditingController(text: widget.initial.remark);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_address.dispose();
|
|
_weather.dispose();
|
|
_temperature.dispose();
|
|
_remark.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
void _submit() {
|
|
Navigator.of(context).pop(
|
|
widget.initial.copyWith(
|
|
address: _address.text.trim(),
|
|
weather: _weather.text.trim(),
|
|
temperature: _temperature.text.trim(),
|
|
remark: _remark.text.trim(),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
// 键盘弹出时把内容顶上去,否则输入框会被挡住
|
|
padding: EdgeInsets.only(bottom: MediaQuery.viewInsetsOf(context).bottom),
|
|
child: SafeArea(
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.fromLTRB(20, 16, 20, 20),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Center(
|
|
child: Text(
|
|
'编辑水印内容',
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
color: Color(0xFF5D4037),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 18),
|
|
|
|
_field(label: '地址', controller: _address, hint: '自动定位,也可手改'),
|
|
_field(label: '天气', controller: _weather, hint: '如:晴'),
|
|
_field(label: '温度', controller: _temperature, hint: '如:25℃'),
|
|
_field(label: '备注', controller: _remark, hint: '想写点什么'),
|
|
|
|
const SizedBox(height: 20),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: SizedBox(
|
|
height: 46,
|
|
child: OutlinedButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
style: OutlinedButton.styleFrom(
|
|
foregroundColor: const Color(0xFFC8956E),
|
|
side: const BorderSide(color: Color(0xFFC8956E)),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(23),
|
|
),
|
|
),
|
|
child: const Text('取消'),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: SizedBox(
|
|
height: 46,
|
|
child: FilledButton(
|
|
onPressed: _submit,
|
|
style: FilledButton.styleFrom(
|
|
backgroundColor: const Color(0xFFC8956E),
|
|
foregroundColor: Colors.white,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(23),
|
|
),
|
|
),
|
|
child: const Text('确定'),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _field({
|
|
required String label,
|
|
required TextEditingController controller,
|
|
required String hint,
|
|
}) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(bottom: 14),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
label,
|
|
style: const TextStyle(fontSize: 13, color: Color(0xFF8D6E63)),
|
|
),
|
|
const SizedBox(height: 6),
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 14),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFFF7F4F1),
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: TextField(
|
|
controller: controller,
|
|
style: const TextStyle(fontSize: 14, color: Color(0xFF5D4037)),
|
|
decoration: InputDecoration(
|
|
border: InputBorder.none,
|
|
isDense: true,
|
|
contentPadding: const EdgeInsets.symmetric(vertical: 13),
|
|
hintText: hint,
|
|
hintStyle: const TextStyle(fontSize: 14, color: Color(0xFFD7CCC8)),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|