dartterm/lib/main.dart
2023-09-22 21:08:03 -07:00

66 lines
1.5 KiB
Dart

import 'package:dartterm/colors.dart';
import 'package:dartterm/input.dart' as input;
import 'package:dartterm/game/game.dart' as game;
import 'package:dartterm/terminal.dart' as terminal;
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
game.main();
runApp(const App());
}
class App extends StatelessWidget {
const App({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'DARTTERM',
theme: ThemeData(
useMaterial3: true, scaffoldBackgroundColor: Palette.defaultBg),
builder: (BuildContext context, Widget? child) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: child!);
},
home: const Viewer(),
);
}
}
class Viewer extends StatefulWidget {
const Viewer({super.key});
@override
State<Viewer> createState() => _ViewerState();
}
class _ViewerState extends State<Viewer> {
Ticker? ticker;
@override
void initState() {
super.initState();
ticker = Ticker(tick);
ticker!.start();
input.startListening();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: AspectRatio(
aspectRatio: terminal.width / terminal.height,
child: terminal.toWidget(context)),
));
}
void tick(Duration elapsed) {
setState(() {/* state changed, force a redraw */});
}
}