112 lines
3.2 KiB
Dart
112 lines
3.2 KiB
Dart
import 'dart:math' as math;
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:trainhub_flutter/core/constants/ui_constants.dart';
|
|
import 'package:trainhub_flutter/core/theme/app_colors.dart';
|
|
|
|
class TypingIndicator extends StatefulWidget {
|
|
const TypingIndicator({super.key});
|
|
|
|
@override
|
|
State<TypingIndicator> createState() => _TypingIndicatorState();
|
|
}
|
|
|
|
class _TypingIndicatorState extends State<TypingIndicator>
|
|
with SingleTickerProviderStateMixin {
|
|
late final AnimationController _controller;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = AnimationController(
|
|
vsync: this,
|
|
duration: const Duration(milliseconds: 1200),
|
|
)..repeat();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(bottom: UIConstants.spacing12),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Container(
|
|
width: 28,
|
|
height: 28,
|
|
decoration: BoxDecoration(
|
|
color: AppColors.surfaceContainerHigh,
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: const Icon(
|
|
Icons.auto_awesome_rounded,
|
|
size: 14,
|
|
color: AppColors.accent,
|
|
),
|
|
),
|
|
const SizedBox(width: UIConstants.spacing8),
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: UIConstants.spacing16,
|
|
vertical: UIConstants.spacing12,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.surfaceContainer,
|
|
borderRadius: const BorderRadius.only(
|
|
topLeft: Radius.circular(16),
|
|
topRight: Radius.circular(16),
|
|
bottomLeft: Radius.circular(4),
|
|
bottomRight: Radius.circular(16),
|
|
),
|
|
border: Border.all(color: AppColors.border, width: 1),
|
|
),
|
|
child: AnimatedBuilder(
|
|
animation: _controller,
|
|
builder: (context, _) {
|
|
return Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: List.generate(3, (index) {
|
|
final delay = index * 0.2;
|
|
final t = (_controller.value - delay) % 1.0;
|
|
final bounce =
|
|
t < 0.5 ? math.sin(t * math.pi * 2) * 4.0 : 0.0;
|
|
return Padding(
|
|
padding: EdgeInsets.only(left: index == 0 ? 0 : 4),
|
|
child: Transform.translate(
|
|
offset: Offset(0, -bounce.abs()),
|
|
child: const _Dot(),
|
|
),
|
|
);
|
|
}),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _Dot extends StatelessWidget {
|
|
const _Dot();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
width: 7,
|
|
height: 7,
|
|
decoration: const BoxDecoration(
|
|
color: AppColors.textMuted,
|
|
shape: BoxShape.circle,
|
|
),
|
|
);
|
|
}
|
|
}
|