main.dart 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import 'package:flutter/material.dart';
  2. import 'package:xterm/xterm.dart';
  3. void main() {
  4. runApp(MyApp());
  5. }
  6. class MyApp extends StatelessWidget {
  7. // This widget is the root of your application.
  8. @override
  9. Widget build(BuildContext context) {
  10. return MaterialApp(
  11. title: 'Flutter Demo',
  12. theme: ThemeData(
  13. // This is the theme of your application.
  14. //
  15. // Try running your application with "flutter run". You'll see the
  16. // application has a blue toolbar. Then, without quitting the app, try
  17. // changing the primarySwatch below to Colors.green and then invoke
  18. // "hot reload" (press "r" in the console where you ran "flutter run",
  19. // or simply save your changes to "hot reload" in a Flutter IDE).
  20. // Notice that the counter didn't reset back to zero; the application
  21. // is not restarted.
  22. primarySwatch: Colors.blue,
  23. // This makes the visual density adapt to the platform that you run
  24. // the app on. For desktop platforms, the controls will be smaller and
  25. // closer together (more dense) than on mobile platforms.
  26. visualDensity: VisualDensity.adaptivePlatformDensity,
  27. ),
  28. home: MyHomePage(title: 'Flutter Demo Home Page'),
  29. );
  30. }
  31. }
  32. class MyHomePage extends StatefulWidget {
  33. MyHomePage({Key key, this.title}) : super(key: key);
  34. // This widget is the home page of your application. It is stateful, meaning
  35. // that it has a State object (defined below) that contains fields that affect
  36. // how it looks.
  37. // This class is the configuration for the state. It holds the values (in this
  38. // case the title) provided by the parent (in this case the App widget) and
  39. // used by the build method of the State. Fields in a Widget subclass are
  40. // always marked "final".
  41. final String title;
  42. @override
  43. _MyHomePageState createState() => _MyHomePageState();
  44. }
  45. class _MyHomePageState extends State<MyHomePage> {
  46. Terminal terminal;
  47. @override
  48. void initState() {
  49. super.initState();
  50. terminal = Terminal(onInput: onInput);
  51. terminal.write('xterm.dart demo');
  52. terminal.write('\r\n');
  53. terminal.write('\$ ');
  54. }
  55. void onInput(String input) {
  56. if (input == '\r') {
  57. terminal.write('\r\n');
  58. terminal.write('\$ ');
  59. } else {
  60. terminal.write(input);
  61. }
  62. }
  63. @override
  64. Widget build(BuildContext context) {
  65. return Scaffold(
  66. body: TerminalView(terminal: terminal),
  67. );
  68. }
  69. }