mirror of
https://gitlab.com/veilid/veilid.git
synced 2025-06-25 15:20:36 -04:00
flutter work
This commit is contained in:
parent
8c96373cfd
commit
a44794ab98
11 changed files with 387 additions and 361 deletions
60
veilid-flutter/example/lib/log_terminal.dart
Normal file
60
veilid-flutter/example/lib/log_terminal.dart
Normal file
|
@ -0,0 +1,60 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:xterm/xterm.dart';
|
||||
import 'log.dart';
|
||||
|
||||
class LogTerminal extends StatefulWidget {
|
||||
const LogTerminal({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
// ignore: library_private_types_in_public_api
|
||||
_LogTerminalState createState() => _LogTerminalState();
|
||||
}
|
||||
|
||||
class _LogTerminalState extends State<LogTerminal> {
|
||||
final terminal = Terminal(
|
||||
maxLines: 10000,
|
||||
);
|
||||
|
||||
final terminalController = TerminalController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
terminal.setLineFeedMode(true);
|
||||
globalTerminalPrinter
|
||||
.setCallback((log) => {terminal.write("${log.pretty()}\n")});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.transparent,
|
||||
body: SafeArea(
|
||||
child: TerminalView(
|
||||
terminal,
|
||||
controller: terminalController,
|
||||
autofocus: true,
|
||||
backgroundOpacity: 0.7,
|
||||
onSecondaryTapDown: (details, offset) async {
|
||||
final selection = terminalController.selection;
|
||||
if (selection != null) {
|
||||
final text = terminal.buffer.getText(selection);
|
||||
terminalController.clearSelection();
|
||||
await Clipboard.setData(ClipboardData(text: text));
|
||||
} else {
|
||||
final data = await Clipboard.getData('text/plain');
|
||||
final text = data?.text;
|
||||
if (text != null) {
|
||||
terminal.paste(text);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue