Restyle the chat composer
Rounded borderless bubble that grows to five lines, one round button that switches between attach and send, reply and GIF previews inside the bubble, a byte counter shown only near the limit, and a transparent panel over chat wallpapers. Sending, limits and compression are unchanged.
This commit is contained in:
1 parent
34ea0cb7ca
commit
bc0062363d
9 files changed
+1241
-251
No files matched your search
@@ -62,6 +62,14 @@ class ByteCountedTextField extends StatelessWidget {
|
||||
final int? softLimitBytes;
|
||||
final String? softLimitNote;
|
||||
|
||||
/// Lines the field grows to before it scrolls internally. Null (the
|
||||
/// default) grows without limit.
|
||||
final int? maxLines;
|
||||
|
||||
/// Show the counter row only once usage passes [warningThreshold], and give
|
||||
/// it no space until then. By default the row keeps its height while hidden.
|
||||
final bool counterOnlyNearLimit;
|
||||
|
||||
const ByteCountedTextField({
|
||||
super.key,
|
||||
required this.maxBytes,
|
||||
@@ -80,6 +88,8 @@ class ByteCountedTextField extends StatelessWidget {
|
||||
this.encoder,
|
||||
this.softLimitBytes,
|
||||
this.softLimitNote,
|
||||
this.maxLines,
|
||||
this.counterOnlyNearLimit = false,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -92,7 +102,9 @@ class ByteCountedTextField extends StatelessWidget {
|
||||
: value.text;
|
||||
final usedBytes = utf8.encode(effectiveText).length;
|
||||
final ratio = maxBytes > 0 ? usedBytes / maxBytes : 0.0;
|
||||
final showCounter = !(hideCounterWhenEmpty && value.text.isEmpty);
|
||||
final showCounter = counterOnlyNearLimit
|
||||
? ratio > warningThreshold
|
||||
: !(hideCounterWhenEmpty && value.text.isEmpty);
|
||||
final showSoftLimitNote =
|
||||
softLimitNote != null &&
|
||||
softLimitBytes != null &&
|
||||
@@ -104,12 +116,27 @@ class ByteCountedTextField extends StatelessWidget {
|
||||
? Theme.of(context).colorScheme.tertiary
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
|
||||
final softNote = showSoftLimitNote
|
||||
? Text(
|
||||
softLimitNote!,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Theme.of(context).colorScheme.tertiary,
|
||||
),
|
||||
)
|
||||
: null;
|
||||
final counter = Text(
|
||||
'$usedBytes / $maxBytes',
|
||||
style: TextStyle(fontSize: 12, color: counterColor),
|
||||
);
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
TextField(
|
||||
maxLines: null,
|
||||
minLines: maxLines == null ? null : 1,
|
||||
maxLines: maxLines,
|
||||
controller: controller,
|
||||
focusNode: focusNode,
|
||||
autofocus: autofocus,
|
||||
@@ -134,32 +161,32 @@ class ByteCountedTextField extends StatelessWidget {
|
||||
textInputAction: textInputAction,
|
||||
onSubmitted: onSubmitted,
|
||||
),
|
||||
Opacity(
|
||||
opacity: showCounter ? 1 : 0,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 4, right: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: showSoftLimitNote
|
||||
? Text(
|
||||
softLimitNote!,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Theme.of(context).colorScheme.tertiary,
|
||||
),
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'$usedBytes / $maxBytes',
|
||||
style: TextStyle(fontSize: 12, color: counterColor),
|
||||
),
|
||||
],
|
||||
if (counterOnlyNearLimit && showCounter)
|
||||
// Right-aligned, and wraps rather than overflowing at large
|
||||
// text sizes in a narrow field.
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 12, 8),
|
||||
child: Wrap(
|
||||
alignment: WrapAlignment.end,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
spacing: 8,
|
||||
children: [?softNote, counter],
|
||||
),
|
||||
)
|
||||
else if (!counterOnlyNearLimit)
|
||||
Opacity(
|
||||
opacity: showCounter ? 1 : 0,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 4, right: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(child: softNote ?? const SizedBox.shrink()),
|
||||
const SizedBox(width: 8),
|
||||
counter,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user