Skip to content

Commit 4a8399c

Browse files
committed
add landscape support
1 parent 8710e90 commit 4a8399c

File tree

10 files changed

+210
-103
lines changed

10 files changed

+210
-103
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ Please view [README_EN](https://github.com/boyan01/flutter-tetris/blob/master/RE
2222

2323
![效果预览](./_preview/game_gif.gif)
2424

25+
支持横屏模式
26+
27+
![横屏](./_preview/screen_land.jpg)
2528

2629

2730
## 其他

README_EN.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ Inspired by [vue-tetris](https://github.com/Binaryify/vue-tetris).
2121

2222
![preview](./_preview/game_gif.gif)
2323

24+
support landscape
25+
26+
![land](./_preview/screen_land.jpg)
27+
2428
## Other
2529

2630
MIT License

_preview/screen_land.jpg

81.5 KB
Loading

lib/main.dart

Lines changed: 6 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import 'package:flutter/material.dart';
22
import 'package:flutter_localizations/flutter_localizations.dart';
33
import 'package:tetris/gamer/gamer.dart';
44
import 'package:tetris/generated/i18n.dart';
5-
import 'package:tetris/income/donation_dialog.dart';
6-
import 'package:tetris/panel/controller.dart';
7-
import 'package:tetris/panel/screen.dart';
5+
import 'package:tetris/panel/page_portrait.dart';
86

97
void main() {
108
_disableDebugPrint();
@@ -51,65 +49,13 @@ class MyApp extends StatelessWidget {
5149

5250
const SCREEN_BORDER_WIDTH = 3.0;
5351

52+
const BACKGROUND_COLOR = const Color(0xffefcc19);
53+
5454
class _HomePage extends StatelessWidget {
5555
@override
5656
Widget build(BuildContext context) {
57-
final size = MediaQuery.of(context).size;
58-
final screenW = size.width * 0.8;
59-
60-
return SizedBox.expand(
61-
child: Container(
62-
color: Color(0xffefcc19),
63-
child: Padding(
64-
padding: MediaQuery.of(context).padding,
65-
child: Column(
66-
children: <Widget>[
67-
Row(
68-
children: <Widget>[
69-
Spacer(),
70-
FlatButton(
71-
onPressed: () {
72-
showDialog(
73-
context: context,
74-
builder: (context) => DonationDialog());
75-
},
76-
child: Text(S.of(context).reward))
77-
],
78-
),
79-
Spacer(),
80-
Container(
81-
decoration: BoxDecoration(
82-
border: Border(
83-
top: BorderSide(
84-
color: const Color(0xFF987f0f),
85-
width: SCREEN_BORDER_WIDTH),
86-
left: BorderSide(
87-
color: const Color(0xFF987f0f),
88-
width: SCREEN_BORDER_WIDTH),
89-
right: BorderSide(
90-
color: const Color(0xFFfae36c),
91-
width: SCREEN_BORDER_WIDTH),
92-
bottom: BorderSide(
93-
color: const Color(0xFFfae36c),
94-
width: SCREEN_BORDER_WIDTH),
95-
),
96-
),
97-
child: Container(
98-
decoration:
99-
BoxDecoration(border: Border.all(color: Colors.black54)),
100-
child: Container(
101-
padding: const EdgeInsets.all(3),
102-
color: SCREEN_BACKGROUND,
103-
child: Screen(width: screenW),
104-
),
105-
),
106-
),
107-
Spacer(flex: 2),
108-
GameController(),
109-
],
110-
),
111-
),
112-
),
113-
);
57+
return MediaQuery.of(context).orientation == Orientation.landscape
58+
? PageLand()
59+
: PagePortrait();
11460
}
11561
}

lib/material/briks.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ class Brik extends StatelessWidget {
4242

4343
@override
4444
Widget build(BuildContext context) {
45+
final width = BrikSize.of(context).size.width;
4546
return SizedBox.fromSize(
4647
size: BrikSize.of(context).size,
4748
child: Container(
48-
margin: EdgeInsets.all(1),
49-
padding: EdgeInsets.all(2),
50-
decoration: BoxDecoration(border: Border.all(width: 2, color: color)),
49+
margin: EdgeInsets.all(0.05 * width),
50+
padding: EdgeInsets.all(0.1 * width),
51+
decoration:
52+
BoxDecoration(border: Border.all(width: 0.10 * width, color: color)),
5153
child: Container(
5254
color: color,
5355
),

lib/panel/controller.dart

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class GameController extends StatelessWidget {
1313
height: 200,
1414
child: Row(
1515
children: <Widget>[
16-
Expanded(child: _LeftController()),
17-
Expanded(child: _DirectionController()),
16+
Expanded(child: LeftController()),
17+
Expanded(child: DirectionController()),
1818
],
1919
),
2020
);
@@ -27,10 +27,11 @@ const Size _SYSTEM_BUTTON_SIZE = const Size(28, 28);
2727

2828
const double _DIRECTION_SPACE = 10;
2929

30-
class _DirectionController extends StatelessWidget {
30+
class DirectionController extends StatelessWidget {
3131
@override
3232
Widget build(BuildContext context) {
33-
return Center(
33+
return SizedBox.fromSize(
34+
size: _DIRECTION_BUTTON_SIZE * 2 * 1.41,
3435
child: Transform.rotate(
3536
angle: math.pi / 4,
3637
child: Column(
@@ -80,45 +81,59 @@ class _DirectionController extends StatelessWidget {
8081
}
8182
}
8283

83-
class _LeftController extends StatelessWidget {
84+
class SystemButtonGroup extends StatelessWidget {
8485
@override
8586
Widget build(BuildContext context) {
86-
return Column(
87+
return Row(
88+
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
8789
children: <Widget>[
88-
Row(
89-
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
90-
children: <Widget>[
91-
_SystemButton(
92-
color: const Color(0xFF2dc421),
93-
label: S.of(context).sounds,
94-
onTap: () {
95-
Game.of(context).soundSwitch();
96-
},
97-
),
98-
_SystemButton(
99-
color: const Color(0xFF2dc421),
100-
label: S.of(context).pause_resume,
101-
onTap: () {
102-
Game.of(context).pauseOrResume();
103-
},
104-
),
105-
_SystemButton(
106-
color: Colors.red,
107-
label: S.of(context).reset,
108-
onTap: () {
109-
Game.of(context).reset();
110-
})
111-
],
90+
_SystemButton(
91+
color: const Color(0xFF2dc421),
92+
label: S.of(context).sounds,
93+
onTap: () {
94+
Game.of(context).soundSwitch();
95+
},
96+
),
97+
_SystemButton(
98+
color: const Color(0xFF2dc421),
99+
label: S.of(context).pause_resume,
100+
onTap: () {
101+
Game.of(context).pauseOrResume();
102+
},
112103
),
104+
_SystemButton(
105+
color: Colors.red,
106+
label: S.of(context).reset,
107+
onTap: () {
108+
Game.of(context).reset();
109+
})
110+
],
111+
);
112+
}
113+
}
114+
115+
class DropButton extends StatelessWidget {
116+
@override
117+
Widget build(BuildContext context) {
118+
return _Button(
119+
enableLongPress: false,
120+
size: Size(90, 90),
121+
onTap: () {
122+
Game.of(context).drop();
123+
});
124+
}
125+
}
126+
127+
class LeftController extends StatelessWidget {
128+
@override
129+
Widget build(BuildContext context) {
130+
return Column(
131+
mainAxisSize: MainAxisSize.min,
132+
children: <Widget>[
133+
SystemButtonGroup(),
113134
Expanded(
114135
child: Center(
115-
child: _Button(
116-
enableLongPress: false,
117-
size: Size(90, 90),
118-
onTap: () {
119-
Game.of(context).drop();
120-
},
121-
),
136+
child: DropButton(),
122137
),
123138
)
124139
],

lib/panel/page_land.dart

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
part of 'page_portrait.dart';
2+
3+
class PageLand extends StatelessWidget {
4+
@override
5+
Widget build(BuildContext context) {
6+
var height = MediaQuery.of(context).size.height;
7+
height -= MediaQuery.of(context).viewInsets.vertical;
8+
return SizedBox.expand(
9+
child: Container(
10+
color: BACKGROUND_COLOR,
11+
child: Padding(
12+
padding: MediaQuery.of(context).padding,
13+
child: Row(
14+
mainAxisSize: MainAxisSize.min,
15+
children: <Widget>[
16+
Expanded(
17+
child: Column(
18+
crossAxisAlignment: CrossAxisAlignment.start,
19+
children: <Widget>[
20+
Spacer(),
21+
SystemButtonGroup(),
22+
Spacer(),
23+
Padding(
24+
padding: const EdgeInsets.only(left: 40, bottom: 40),
25+
child: DropButton(),
26+
)
27+
],
28+
),
29+
),
30+
_ScreenDecoration(child: Screen.fromHeight(height * 0.8)),
31+
Expanded(
32+
child: Column(
33+
children: <Widget>[
34+
Row(
35+
children: <Widget>[
36+
Spacer(),
37+
FlatButton(
38+
onPressed: () {
39+
showDialog(
40+
context: context,
41+
builder: (context) => DonationDialog());
42+
},
43+
child: Text(S.of(context).reward))
44+
],
45+
),
46+
Spacer(),
47+
DirectionController(),
48+
],
49+
),
50+
),
51+
],
52+
),
53+
),
54+
),
55+
);
56+
}
57+
}

lib/panel/page_portrait.dart

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:tetris/generated/i18n.dart';
3+
import 'package:tetris/income/donation_dialog.dart';
4+
import 'package:tetris/main.dart';
5+
import 'package:tetris/panel/controller.dart';
6+
import 'package:tetris/panel/screen.dart';
7+
8+
part 'page_land.dart';
9+
10+
class PagePortrait extends StatelessWidget {
11+
@override
12+
Widget build(BuildContext context) {
13+
final size = MediaQuery.of(context).size;
14+
final screenW = size.width * 0.8;
15+
16+
return SizedBox.expand(
17+
child: Container(
18+
color: BACKGROUND_COLOR,
19+
child: Padding(
20+
padding: MediaQuery.of(context).padding,
21+
child: Column(
22+
children: <Widget>[
23+
Row(
24+
children: <Widget>[
25+
Spacer(),
26+
FlatButton(
27+
onPressed: () {
28+
showDialog(
29+
context: context,
30+
builder: (context) => DonationDialog());
31+
},
32+
child: Text(S.of(context).reward))
33+
],
34+
),
35+
Spacer(),
36+
_ScreenDecoration(child: Screen(width: screenW)),
37+
Spacer(flex: 2),
38+
GameController(),
39+
],
40+
),
41+
),
42+
),
43+
);
44+
}
45+
}
46+
47+
class _ScreenDecoration extends StatelessWidget {
48+
final Widget child;
49+
50+
const _ScreenDecoration({Key key, @required this.child}) : super(key: key);
51+
52+
@override
53+
Widget build(BuildContext context) {
54+
return Container(
55+
decoration: BoxDecoration(
56+
border: Border(
57+
top: BorderSide(
58+
color: const Color(0xFF987f0f), width: SCREEN_BORDER_WIDTH),
59+
left: BorderSide(
60+
color: const Color(0xFF987f0f), width: SCREEN_BORDER_WIDTH),
61+
right: BorderSide(
62+
color: const Color(0xFFfae36c), width: SCREEN_BORDER_WIDTH),
63+
bottom: BorderSide(
64+
color: const Color(0xFFfae36c), width: SCREEN_BORDER_WIDTH),
65+
),
66+
),
67+
child: Container(
68+
decoration: BoxDecoration(border: Border.all(color: Colors.black54)),
69+
child: Container(
70+
padding: const EdgeInsets.all(3),
71+
color: SCREEN_BACKGROUND,
72+
child: child,
73+
),
74+
),
75+
);
76+
}
77+
}

lib/panel/player_panel.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class PlayerPanel extends StatelessWidget {
2121

2222
@override
2323
Widget build(BuildContext context) {
24+
debugPrint("size : $size");
2425
return SizedBox.fromSize(
2526
size: size,
2627
child: Container(

0 commit comments

Comments
 (0)