| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- import 'dart:convert';
- import 'package:dartssh/client.dart';
- import 'package:flutter/material.dart';
- import 'package:xterm/flutter.dart';
- import 'package:xterm/xterm.dart';
- const host = 'ssh://localhost:22';
- const username = 'xuty';
- const password = '123123';
- void main() {
- runApp(MyApp());
- }
- class MyApp extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'xterm.dart demo',
- theme: ThemeData(
- primarySwatch: Colors.blue,
- visualDensity: VisualDensity.adaptivePlatformDensity,
- ),
- home: MyHomePage(),
- );
- }
- }
- class MyHomePage extends StatefulWidget {
- MyHomePage({Key key}) : super(key: key);
- @override
- _MyHomePageState createState() => _MyHomePageState();
- }
- class _MyHomePageState extends State<MyHomePage> {
- Terminal terminal;
- SSHClient client;
- @override
- void initState() {
- super.initState();
- terminal = Terminal(onInput: onInput);
- connect();
- }
- void connect() {
- terminal.write('connecting $host...');
- client = SSHClient(
- hostport: Uri.parse(host),
- login: username,
- print: print,
- termWidth: 80,
- termHeight: 25,
- termvar: 'xterm-256color',
- getPassword: () => utf8.encode(password),
- response: (transport, data) {
- terminal.write(data);
- },
- success: () {
- terminal.write('connected.\n');
- },
- disconnected: () {
- terminal.write('disconnected.');
- },
- );
- }
- void onInput(String input) {
- client?.sendChannelData(utf8.encode(input));
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: SafeArea(
- child: TerminalView(
- terminal: terminal,
- onResize: (width, height) {
- client?.setTerminalWindowSize(width, height);
- },
- ),
- ),
- );
- }
- }
|