183 lines
5.5 KiB
Dart
183 lines
5.5 KiB
Dart
import 'dart:math' as math;
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'chat_adaptive.dart';
|
|
|
|
/// Hierarchical row copy shared by the Material and Cupertino list variants.
|
|
/// Metadata stays on the left; recency and native actions share its vertical
|
|
/// space on the right instead of adding full-width rows below it.
|
|
class ChatSessionRowContent extends StatelessWidget {
|
|
const ChatSessionRowContent({
|
|
super.key,
|
|
required this.title,
|
|
required this.status,
|
|
required this.recency,
|
|
required this.meta,
|
|
required this.titleStyle,
|
|
required this.metaStyle,
|
|
required this.statusStyle,
|
|
this.loading = false,
|
|
this.leading,
|
|
this.actions = const [],
|
|
});
|
|
|
|
final String title;
|
|
final String? status;
|
|
final String? recency;
|
|
final List<String> meta;
|
|
final TextStyle titleStyle;
|
|
final TextStyle metaStyle;
|
|
final TextStyle statusStyle;
|
|
final bool loading;
|
|
final Widget? leading;
|
|
final List<Widget> actions;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
if (leading != null) ...[leading!, const SizedBox(width: 8)],
|
|
Expanded(
|
|
child: Text(
|
|
title,
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: titleStyle,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
final hasTrailing =
|
|
actions.isNotEmpty || (recency?.isNotEmpty ?? false);
|
|
final nativeTarget =
|
|
chatControlsStyleOf(context) == ChatControlsStyle.cupertino
|
|
? kMinInteractiveDimensionCupertino
|
|
: kMinInteractiveDimension;
|
|
final trailingWidth = math.min(
|
|
constraints.maxWidth,
|
|
math.max(
|
|
nativeTarget,
|
|
math.min(
|
|
constraints.maxWidth * 0.45,
|
|
nativeTarget * math.max(1, actions.length),
|
|
),
|
|
),
|
|
);
|
|
return Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
if (status != null)
|
|
_StatusLabel(status: status!, style: statusStyle),
|
|
if (status == null && loading)
|
|
Semantics(
|
|
label: 'Chat is working',
|
|
child: const _LoadingStatus(),
|
|
),
|
|
for (final line in meta)
|
|
Text(
|
|
line,
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: metaStyle,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (hasTrailing)
|
|
SizedBox(
|
|
width: trailingWidth,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
if (recency?.isNotEmpty ?? false)
|
|
Text(
|
|
recency!,
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
textAlign: TextAlign.end,
|
|
style: metaStyle,
|
|
),
|
|
if (actions.isNotEmpty)
|
|
Wrap(alignment: WrapAlignment.end, children: actions),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _LoadingStatus extends StatelessWidget {
|
|
const _LoadingStatus();
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
|
|
return const Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: CupertinoActivityIndicator(radius: 7),
|
|
);
|
|
}
|
|
return const Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: SizedBox(
|
|
width: 16,
|
|
height: 16,
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _StatusLabel extends StatelessWidget {
|
|
const _StatusLabel({required this.status, required this.style});
|
|
|
|
final String status;
|
|
final TextStyle style;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (status != 'New') {
|
|
return Text(
|
|
status,
|
|
maxLines: 1,
|
|
style: style.copyWith(fontWeight: FontWeight.w600),
|
|
);
|
|
}
|
|
final color = style.color ?? Theme.of(context).colorScheme.primary;
|
|
return DecoratedBox(
|
|
key: const Key('chat-row-unread'),
|
|
decoration: ShapeDecoration(color: color, shape: const StadiumBorder()),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 1),
|
|
child: Text(
|
|
status,
|
|
maxLines: 1,
|
|
style: style.copyWith(
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|