-
Notifications
You must be signed in to change notification settings - Fork 1
/
message_area.dart
136 lines (131 loc) · 5.31 KB
/
message_area.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import 'package:flutter/material.dart';
// メッセージ入力欄のWidget
class MessageArea extends StatefulWidget {
const MessageArea({
super.key,
required this.focusNode,
required this.textController,
});
final FocusNode focusNode;
final TextEditingController textController;
@override
State<MessageArea> createState() => _MessageAreaState();
}
class _MessageAreaState extends State<MessageArea> {
// テキストが入力されているかどうかのフラグ
bool hasText = false;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.transparent,
body: SafeArea(
child: Stack(
fit: StackFit.expand,
children: [
Positioned(
bottom: 0,
right: 0,
left: 0,
child: Row(
children: <Widget>[
Flexible(
child: Padding(
padding: const EdgeInsets.all(
8,
),
child: TextField(
focusNode: widget.focusNode,
controller: widget.textController,
maxLines: 4,
minLines: 1,
decoration: InputDecoration(
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 16,
),
hintText: 'メッセージを送信',
hintStyle:
Theme.of(context).textTheme.bodyLarge?.copyWith(
color: Colors.white,
fontSize: 16,
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(24),
borderSide: const BorderSide(color: Colors.white),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(24),
borderSide: const BorderSide(color: Colors.white),
),
suffixIcon: widget.focusNode.hasFocus
? hasText
? TextButton(
onPressed: () {
// バックエンド等にメッセージ送信する
debugPrint(widget.textController.text);
},
child: Text(
'送信',
style: Theme.of(
context,
).textTheme.bodyLarge?.copyWith(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
)
: IconButton(
onPressed: () {},
icon: const Icon(
Icons.gif_box_outlined,
color: Colors.white,
size: 32,
),
)
: const SizedBox.shrink(),
),
style: Theme.of(context)
.textTheme
.bodyLarge
?.copyWith(color: Colors.white, fontSize: 16),
onChanged: (value) {
setState(() {
hasText = value.isNotEmpty;
});
},
),
),
),
widget.focusNode.hasFocus
? const SizedBox.shrink()
: Row(
children: [
IconButton(
icon: const Icon(
Icons.favorite_border,
color: Colors.white,
),
onPressed: () => {},
),
IconButton(
icon: const Icon(
Icons.send,
color: Colors.white,
),
onPressed: () => {
// バックエンド等にメッセージ送信する
debugPrint(widget.textController.text),
},
),
],
),
],
),
),
],
),
),
);
}
}