Show definition and run warnings in app summaries
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../adaptive/host.dart';
|
||||
|
||||
import 'section_heading.dart';
|
||||
|
||||
/// Protocol warning arrays contain human-readable strings. Ignore malformed
|
||||
/// entries rather than displaying map/list representations as diagnostics.
|
||||
List<String> warningMessages(Object? value) => value is List
|
||||
? value
|
||||
.whereType<String>()
|
||||
.map((message) => message.trim())
|
||||
.where((message) => message.isNotEmpty)
|
||||
.toList(growable: false)
|
||||
: const [];
|
||||
|
||||
/// A visible, selectable group of server diagnostics; no collapsed disclosure
|
||||
/// hides a warning from the operator reading the summary.
|
||||
class WarningsSection extends StatelessWidget {
|
||||
const WarningsSection({
|
||||
super.key,
|
||||
required this.messages,
|
||||
this.title = 'Warnings',
|
||||
});
|
||||
|
||||
final List<String> messages;
|
||||
final String title;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => messages.isEmpty
|
||||
? const SizedBox.shrink()
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
SectionHeading(title: title, header: true),
|
||||
for (final message in messages)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 16, 8),
|
||||
child: usesCupertinoHost(context)
|
||||
? _CupertinoWarningText(message)
|
||||
: SelectableText(message),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
class _CupertinoWarningText extends StatefulWidget {
|
||||
const _CupertinoWarningText(this.message);
|
||||
final String message;
|
||||
|
||||
@override
|
||||
State<_CupertinoWarningText> createState() => _CupertinoWarningTextState();
|
||||
}
|
||||
|
||||
class _CupertinoWarningTextState extends State<_CupertinoWarningText> {
|
||||
late final _controller = TextEditingController(text: widget.message);
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant _CupertinoWarningText oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.message != oldWidget.message) _controller.text = widget.message;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => CupertinoTextField(
|
||||
controller: _controller,
|
||||
readOnly: true,
|
||||
maxLines: null,
|
||||
padding: EdgeInsets.zero,
|
||||
decoration: const BoxDecoration(),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user