init
This commit is contained in:
65
lib/app/features/modals/send_text_modal.dart
Normal file
65
lib/app/features/modals/send_text_modal.dart
Normal file
@@ -0,0 +1,65 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../backend/api/commands.dart' as commands;
|
||||
import '../../../backend/discovery/model.dart';
|
||||
|
||||
class SendTextModal extends StatefulWidget {
|
||||
const SendTextModal({super.key, required this.peer, required this.targetIp});
|
||||
|
||||
final Peer peer;
|
||||
final String targetIp;
|
||||
|
||||
@override
|
||||
State<SendTextModal> createState() => _SendTextModalState();
|
||||
}
|
||||
|
||||
class _SendTextModalState extends State<SendTextModal> {
|
||||
final _controller = TextEditingController();
|
||||
|
||||
Future<void> _submit() async {
|
||||
final text = _controller.text.trim();
|
||||
if (text.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
commands.sendText(
|
||||
target: widget.peer,
|
||||
targetIp: widget.targetIp,
|
||||
text: text,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text('发送文本给 ${widget.peer.name}'),
|
||||
content: SizedBox(
|
||||
width: 540,
|
||||
child: TextField(
|
||||
controller: _controller,
|
||||
maxLines: 8,
|
||||
minLines: 4,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '输入你想发送的文本内容',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
FilledButton.icon(
|
||||
onPressed: _submit,
|
||||
icon: const Icon(Icons.send_rounded),
|
||||
label: const Text('发送'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user