feat(chat): rotate the Stop icon slowly while processing
This commit is contained in:
@@ -3,6 +3,7 @@ import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'chat_stop_icon.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
@@ -937,10 +938,11 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
sizeStyle: CupertinoButtonSize.small,
|
||||
color: stop ? CupertinoColors.systemRed.resolveFrom(context) : null,
|
||||
onPressed: enabled ? press : null,
|
||||
child: Icon(
|
||||
stop ? CupertinoIcons.stop_fill : CupertinoIcons.arrow_up,
|
||||
size: 18,
|
||||
),
|
||||
child: stop
|
||||
? const ChatStopIcon(
|
||||
child: Icon(CupertinoIcons.stop_fill, size: 18),
|
||||
)
|
||||
: const Icon(CupertinoIcons.arrow_up, size: 18),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -955,7 +957,9 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
)
|
||||
: null,
|
||||
onPressed: enabled ? press : null,
|
||||
icon: Icon(stop ? Icons.stop : Icons.send),
|
||||
icon: stop
|
||||
? const ChatStopIcon(child: Icon(Icons.stop))
|
||||
: const Icon(Icons.send),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// Slow, continuous progress motion confined to the Stop glyph. The native
|
||||
/// button, hit target and semantics never rotate. TickerMode pauses hidden UI.
|
||||
class ChatStopIcon extends StatefulWidget {
|
||||
const ChatStopIcon({super.key, required this.child});
|
||||
|
||||
final Widget child;
|
||||
static const period = Duration(seconds: 8);
|
||||
|
||||
@override
|
||||
State<ChatStopIcon> createState() => _ChatStopIconState();
|
||||
}
|
||||
|
||||
class _ChatStopIconState extends State<ChatStopIcon>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final _rotation = AnimationController(
|
||||
vsync: this,
|
||||
duration: ChatStopIcon.period,
|
||||
);
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
if (MediaQuery.maybeDisableAnimationsOf(context) ?? false) {
|
||||
_rotation.stop();
|
||||
_rotation.value = 0;
|
||||
} else if (!_rotation.isAnimating) {
|
||||
_rotation.repeat();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_rotation.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => RepaintBoundary(
|
||||
key: const Key('chat-stop-paint-boundary'),
|
||||
child: RotationTransition(
|
||||
key: const Key('chat-stop-rotation'),
|
||||
turns: _rotation,
|
||||
child: widget.child,
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user