66 lines
2.1 KiB
Dart
66 lines
2.1 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
/// Submit and optional decline/cancel controls for a pending question.
|
|
///
|
|
/// The web shows `Confirm completion` when every field is external, otherwise
|
|
/// `Send answer`, and offers only the actions the form records. The labels are
|
|
/// passed in so this file stays layout only.
|
|
Widget chatQuestionControls({
|
|
required BuildContext context,
|
|
required bool cupertino,
|
|
required Object? actions,
|
|
required String submitLabel,
|
|
required bool sending,
|
|
required VoidCallback onSubmit,
|
|
required void Function(String action) onAction,
|
|
}) {
|
|
final canDecline = actions is List && actions.contains('decline');
|
|
final canCancel = actions is List && actions.contains('cancel');
|
|
if (cupertino) {
|
|
return Wrap(
|
|
spacing: 8,
|
|
runSpacing: 8,
|
|
children: [
|
|
CupertinoButton.filled(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
onPressed: sending ? null : onSubmit,
|
|
child: Text(sending ? 'Sending…' : submitLabel),
|
|
),
|
|
if (canDecline)
|
|
CupertinoButton(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
|
onPressed: sending ? null : () => onAction('decline'),
|
|
child: const Text('Decline'),
|
|
),
|
|
if (canCancel)
|
|
CupertinoButton(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
|
onPressed: sending ? null : () => onAction('cancel'),
|
|
child: const Text('Cancel question'),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
return Wrap(
|
|
spacing: 8,
|
|
runSpacing: 8,
|
|
children: [
|
|
FilledButton(
|
|
onPressed: sending ? null : onSubmit,
|
|
child: Text(sending ? 'Sending…' : submitLabel),
|
|
),
|
|
if (canDecline)
|
|
TextButton(
|
|
onPressed: sending ? null : () => onAction('decline'),
|
|
child: const Text('Decline'),
|
|
),
|
|
if (canCancel)
|
|
TextButton(
|
|
onPressed: sending ? null : () => onAction('cancel'),
|
|
child: const Text('Cancel question'),
|
|
),
|
|
],
|
|
);
|
|
}
|