9551eceaed
Remove obsolete control-family flags and icon metadata across all callers, dead alternate themes and host helpers, obsolete test setup, and the unused icon-font dependency. Preserve native Material Back transitions. Make navigation fixtures independent of update plugins and answer auxiliary shell snapshots so the complete application suite can run deterministically.
147 lines
4.3 KiB
Dart
147 lines
4.3 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../domain/chat_account_usage.dart';
|
|
|
|
/// The info sheet's "Account usage" section: one progress bar per quota
|
|
/// window the harness reported, the plan and the report's age. It draws
|
|
/// nothing for an unknown quota, and one muted line when the harness has no
|
|
/// quota API. Reset countdowns tick while the sheet is open.
|
|
class ChatAccountUsageSection extends StatefulWidget {
|
|
const ChatAccountUsageSection({
|
|
super.key,
|
|
required this.usage,
|
|
this.now = DateTime.now,
|
|
});
|
|
|
|
final ChatAccountUsage? usage;
|
|
final DateTime Function() now;
|
|
|
|
@override
|
|
State<ChatAccountUsageSection> createState() =>
|
|
_ChatAccountUsageSectionState();
|
|
}
|
|
|
|
class _ChatAccountUsageSectionState extends State<ChatAccountUsageSection> {
|
|
Timer? _tick;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_tick = Timer.periodic(const Duration(seconds: 30), (_) {
|
|
if (mounted) setState(() {});
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_tick?.cancel();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final usage = widget.usage;
|
|
if (usage == null) return const SizedBox.shrink();
|
|
final now = widget.now();
|
|
final secondary = Theme.of(context).colorScheme.onSurfaceVariant;
|
|
final body = Theme.of(context).textTheme.bodyMedium;
|
|
final title = Theme.of(context).textTheme.titleSmall;
|
|
final muted = body?.copyWith(color: secondary);
|
|
final asOf = chatQuotaAsOf(usage.asOf, now);
|
|
final plan = chatPlanLabel(usage.plan);
|
|
return Padding(
|
|
key: const Key('chat-account-usage'),
|
|
padding: const EdgeInsetsDirectional.fromSTEB(24, 12, 24, 6),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Text('Account usage', style: title),
|
|
if (usage.unsupported)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 4),
|
|
child: Text(
|
|
'Not reported by ${usage.harness}',
|
|
key: const Key('chat-account-usage-unsupported'),
|
|
style: muted,
|
|
),
|
|
)
|
|
else ...[
|
|
if (plan.isNotEmpty)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 4),
|
|
child: Text(
|
|
usage.harness.isEmpty
|
|
? '$plan plan'
|
|
: '${usage.harness} · $plan plan',
|
|
key: const Key('chat-account-usage-plan'),
|
|
style: muted,
|
|
),
|
|
),
|
|
for (final window in usage.windows)
|
|
_QuotaWindowRow(
|
|
window: window,
|
|
now: now,
|
|
body: body,
|
|
muted: muted,
|
|
),
|
|
if (asOf.isNotEmpty)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 6),
|
|
child: Text(
|
|
asOf,
|
|
key: const Key('chat-account-usage-as-of'),
|
|
style: muted,
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _QuotaWindowRow extends StatelessWidget {
|
|
const _QuotaWindowRow({
|
|
required this.window,
|
|
required this.now,
|
|
required this.body,
|
|
required this.muted,
|
|
});
|
|
|
|
final ChatQuotaWindow window;
|
|
final DateTime now;
|
|
final TextStyle? body;
|
|
final TextStyle? muted;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final summary = chatQuotaSummary(window, now);
|
|
final fraction = (window.usedPercent / 100).clamp(0.0, 1.0);
|
|
final high = window.usedPercent >= 90;
|
|
final bar = LinearProgressIndicator(
|
|
value: fraction,
|
|
color: high ? Theme.of(context).colorScheme.error : null,
|
|
borderRadius: BorderRadius.circular(2),
|
|
semanticsLabel: '${window.label} quota',
|
|
);
|
|
return Padding(
|
|
key: Key('chat-account-window-${window.id}'),
|
|
padding: const EdgeInsets.only(top: 8),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Text(window.label, style: body),
|
|
Padding(padding: const EdgeInsets.symmetric(vertical: 4), child: bar),
|
|
Text(
|
|
summary,
|
|
key: Key('chat-account-window-summary-${window.id}'),
|
|
style: muted,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|