-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.dart
99 lines (90 loc) · 3.41 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import 'package:flutter/material.dart';
import 'package:gol_grid/gol_grid.dart';
import 'package:grid_world/grid_world.dart';
import 'package:thumper/thumper.dart';
// ignore_for_file: diagnostic_describe_all_properties
// ignore_for_file: use_key_in_widget_constructors
void main() => runApp(const DemoApp());
/// A GolGrid widget demo.
@immutable
class DemoApp extends StatelessWidget {
/// Make an app instance.
const DemoApp({this.isFullScreen = true});
/// Full screen consumes lots of pixels/CPU - best for Android.
final bool isFullScreen;
static const _spacer = SizedBox(height: 3);
@override
Widget build(BuildContext context) => MaterialApp(
title: 'Game of Life Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
backgroundColor: Colors.grey,
appBar: AppBar(
title: const Text('Game of Life Demo'),
leading: Icon(Icons.menu),
),
body: isFullScreen ? FullScreenWidget() : _widgetColumn()),
);
Widget _widgetColumn() => Center(
child: ListView(children: <Widget>[
_spacer,
GolGrid(DimensionedWorld.make(ConwayEvolver.blinker.lrPadded(6),
lineWidth: 10, cellWidth: 30)),
_spacer,
GolGrid(
DimensionedWorld.make(ConwayEvolver.pentaDecathlon.clockwise90(),
lineWidth: 6, cellWidth: 18),
foregroundColor: Colors.deepPurple),
_spacer,
GolGrid(DimensionedWorld.make(
ConwayEvolver.lightweightSpaceship
.appendBottom(ConwayEvolver.lightweightSpaceship)
.appendBottom(ConwayEvolver.lightweightSpaceship)
.padRight(50),
lineWidth: 3,
cellWidth: 9)),
_spacer,
GolGrid(
DimensionedWorld.make(
ConwayEvolver.gliderFleet().padRight(20).padBottom(30),
lineWidth: 3,
cellWidth: 9),
foregroundColor: Colors.redAccent),
_spacer,
GolGrid(DimensionedWorld.make(
ConwayEvolver.gosperGliderGun.padded(20),
lineWidth: 3,
cellWidth: 9)),
_spacer,
GolGrid(
DimensionedWorld.make(
ConwayEvolver.rPentimino.lrPadded(70).tbPadded(60),
lineWidth: 1,
cellWidth: 3),
foregroundColor: Colors.white),
_spacer,
]),
);
}
/// [FullScreenWidget] does a media query to expand a [DimensionedWorld]
/// to fill the media.
///
/// The query only works if this widget is below [MaterialApp] in the tree.
class FullScreenWidget extends StatelessWidget {
/// A guess as to the media height (virtual pixels) consumed by the AppBar.
/// TODO: Instead of guessing, look up the appbar via a key, e.g.
/// medium.com/@diegoveloper/flutter-widget-size-and-position-b0a9ffed9407
static double get _estimatedAppBarHeight => 80; // 80
@override
Widget build(BuildContext context) {
final s = MediaQuery.of(context).size;
final dw = DimensionedWorld.make(ConwayEvolver.gunFight()
.appendBottom(ConwayEvolver.rPentimino.padLeft(30).tbPadded(27))
.appendBottom(ConwayEvolver.gunFight())
.lrPadded(6));
return GolGrid(dw.expandToFit(
s.width, s.height - _estimatedAppBarHeight - Thumper.height));
}
}