mirror of
https://github.com/foss42/apidash.git
synced 2025-08-06 13:51:20 +08:00
Adding stand-alone widgets
This commit is contained in:
30
lib/widgets/buttons.dart
Normal file
30
lib/widgets/buttons.dart
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
class CopyButton extends StatefulWidget {
|
||||||
|
const CopyButton({super.key, required this.toCopy});
|
||||||
|
|
||||||
|
final String toCopy;
|
||||||
|
@override
|
||||||
|
State<CopyButton> createState() => _CopyButtonState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CopyButtonState extends State<CopyButton> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return TextButton(
|
||||||
|
onPressed: () async {
|
||||||
|
await Clipboard.setData(ClipboardData(text: widget.toCopy));
|
||||||
|
},
|
||||||
|
child: Row(
|
||||||
|
children: const [
|
||||||
|
Icon(
|
||||||
|
Icons.content_copy,
|
||||||
|
size: 20,
|
||||||
|
),
|
||||||
|
Text("Copy")
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
36
lib/widgets/error_message.dart
Normal file
36
lib/widgets/error_message.dart
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import 'package:apidash/consts.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class ErrorMessage extends StatelessWidget {
|
||||||
|
const ErrorMessage({super.key, required this.message});
|
||||||
|
|
||||||
|
final String? message;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final color = Theme.of(context).colorScheme.secondary;
|
||||||
|
return Padding(
|
||||||
|
padding: kPh20v10,
|
||||||
|
child: Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.warning_rounded,
|
||||||
|
size: 40,
|
||||||
|
color: color,
|
||||||
|
),
|
||||||
|
SelectableText(
|
||||||
|
message ?? 'And error occurred. $kRaiseIssue',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.titleMedium
|
||||||
|
?.copyWith(color: color),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
43
lib/widgets/previewer.dart
Normal file
43
lib/widgets/previewer.dart
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:apidash/consts.dart';
|
||||||
|
|
||||||
|
class Previewer extends StatefulWidget {
|
||||||
|
const Previewer(
|
||||||
|
{super.key,
|
||||||
|
required this.bytes,
|
||||||
|
required this.type,
|
||||||
|
required this.subtype});
|
||||||
|
|
||||||
|
final Uint8List bytes;
|
||||||
|
final String type;
|
||||||
|
final String subtype;
|
||||||
|
@override
|
||||||
|
State<Previewer> createState() => _PreviewerState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PreviewerState extends State<Previewer> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (widget.type == kTypeApplication && widget.subtype == kSubTypePdf) {
|
||||||
|
return const SelectableText("PDF viewing $kMimeTypeRaiseIssue");
|
||||||
|
}
|
||||||
|
if (widget.type == kTypeImage) {
|
||||||
|
return Image.memory(
|
||||||
|
widget.bytes,
|
||||||
|
errorBuilder: (context, _, stackTrace) {
|
||||||
|
return SelectableText(
|
||||||
|
"${widget.type}/${widget.subtype} mimetype preview $kMimeTypeRaiseIssue");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (widget.type == kTypeAudio) {
|
||||||
|
return const SelectableText("Audio playing $kMimeTypeRaiseIssue");
|
||||||
|
}
|
||||||
|
if (widget.type == kTypeVideo) {
|
||||||
|
return const SelectableText("Video playing $kMimeTypeRaiseIssue");
|
||||||
|
}
|
||||||
|
return SelectableText(
|
||||||
|
"${widget.type}/${widget.subtype} mimetype preview $kMimeTypeRaiseIssue");
|
||||||
|
}
|
||||||
|
}
|
89
lib/widgets/tables.dart
Normal file
89
lib/widgets/tables.dart
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:apidash/utils/utils.dart';
|
||||||
|
import 'package:apidash/consts.dart';
|
||||||
|
|
||||||
|
class MapTable extends StatefulWidget {
|
||||||
|
const MapTable(
|
||||||
|
{super.key,
|
||||||
|
required this.map,
|
||||||
|
required this.colNames,
|
||||||
|
this.firstColumnHeaderCase = false});
|
||||||
|
|
||||||
|
final Map map;
|
||||||
|
final List<String> colNames;
|
||||||
|
final bool firstColumnHeaderCase;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<MapTable> createState() => _MapTableState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MapTableState extends State<MapTable> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Table(
|
||||||
|
border: TableBorder(
|
||||||
|
horizontalInside: BorderSide(
|
||||||
|
color: Theme.of(context).colorScheme.surfaceVariant,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
columnWidths: const <int, TableColumnWidth>{
|
||||||
|
0: FlexColumnWidth(),
|
||||||
|
1: FlexColumnWidth(),
|
||||||
|
},
|
||||||
|
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
|
||||||
|
children: [
|
||||||
|
TableRow(
|
||||||
|
children: widget.colNames
|
||||||
|
.map<TableCell>(
|
||||||
|
(e) => TableCell(
|
||||||
|
verticalAlignment: TableCellVerticalAlignment.top,
|
||||||
|
child: Padding(
|
||||||
|
padding: kP1,
|
||||||
|
child: SelectableText(
|
||||||
|
e,
|
||||||
|
style: kCodeStyle.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Theme.of(context).colorScheme.primary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList(),
|
||||||
|
),
|
||||||
|
...widget.map.entries
|
||||||
|
.map<TableRow>(
|
||||||
|
(entry) => TableRow(
|
||||||
|
children: [
|
||||||
|
TableCell(
|
||||||
|
verticalAlignment: TableCellVerticalAlignment.top,
|
||||||
|
child: Padding(
|
||||||
|
padding: kP1,
|
||||||
|
child: SelectableText(
|
||||||
|
widget.firstColumnHeaderCase
|
||||||
|
? formatHeaderCase(entry.key)
|
||||||
|
: entry.key,
|
||||||
|
style: kCodeStyle.copyWith(
|
||||||
|
color: Theme.of(context).colorScheme.tertiary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TableCell(
|
||||||
|
verticalAlignment: TableCellVerticalAlignment.top,
|
||||||
|
child: Padding(
|
||||||
|
padding: kP1,
|
||||||
|
child: SelectableText(
|
||||||
|
entry.value,
|
||||||
|
style: kCodeStyle,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList(),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
6
lib/widgets/widgets.dart
Normal file
6
lib/widgets/widgets.dart
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export 'editor.dart';
|
||||||
|
export 'code_highlighter.dart';
|
||||||
|
export 'buttons.dart';
|
||||||
|
export 'tables.dart';
|
||||||
|
export 'previewer.dart';
|
||||||
|
export 'error_message.dart';
|
Reference in New Issue
Block a user