Quickstart: Create and display a terminal
masterTo implement a basic terminal, follow these steps:
- Initialize a
Terminalinstance. - (Optional) Set an
onOutputcallback to handle user input/interaction. - Use
TerminalViewfrompackage:xterm/flutter.dartto render the terminal in your Flutter widget tree. - Use
terminal.write()to send text to the terminal buffer.
import 'package:xterm/xterm.dart';
import 'package:xterm/flutter.dart';
// 1. Create the terminal
final terminal = Terminal();
// 2. Listen to user interaction
terminal.onOutput = (output) {
print('output: $output');
};
// 3. In your Widget build method:
// child: TerminalView(terminal),
// 4. Write to the terminal
terminal.write('Hello, world!');