Skip to content

Commit 8710e90

Browse files
committed
add reward dialog
1 parent aff490d commit 8710e90

File tree

9 files changed

+173
-15
lines changed

9 files changed

+173
-15
lines changed

assets/alipay.jpg

236 KB
Loading

assets/wechat.png

135 KB
Loading

lib/gamer/gamer.dart

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:async';
22

33
import 'package:flutter/material.dart';
44
import 'package:tetris/gamer/block.dart';
5+
import 'package:tetris/main.dart';
56
import 'package:tetris/material/audios.dart';
67

78
///the height of game pad
@@ -73,7 +74,7 @@ const _SPEED = [
7374
const Duration(milliseconds: 160),
7475
];
7576

76-
class GameControl extends State<Game> {
77+
class GameControl extends State<Game> with RouteAware {
7778
GameControl() {
7879
//inflate game pad data
7980
for (int i = 0; i < GAME_PAD_MATRIX_H; i++) {
@@ -82,6 +83,24 @@ class GameControl extends State<Game> {
8283
}
8384
}
8485

86+
@override
87+
void didChangeDependencies() {
88+
super.didChangeDependencies();
89+
routeObserver.subscribe(this, ModalRoute.of(context));
90+
}
91+
92+
@override
93+
void dispose() {
94+
routeObserver.unsubscribe(this);
95+
super.dispose();
96+
}
97+
98+
@override
99+
void didPushNext() {
100+
//pause when screen is at background
101+
pause();
102+
}
103+
85104
///the gamer data
86105
final List<List<int>> _data = [];
87106

@@ -320,6 +339,7 @@ class GameControl extends State<Game> {
320339
return line != 0;
321340
});
322341
_current = null;
342+
_getNext();
323343
_points = 0;
324344
_cleared = 0;
325345
await Future.doWhile(() async {

lib/generated/i18n.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class S implements WidgetsLocalizations {
2525
String get pause_resume => "PAUSE/RESUME";
2626
String get points => "Points";
2727
String get reset => "RESET";
28+
String get reward => "Reward";
2829
String get sounds => "SOUNDS";
2930
}
3031

@@ -41,6 +42,8 @@ class $zh_CN extends S {
4142
@override
4243
String get next => "下一个";
4344
@override
45+
String get reward => "赞赏";
46+
@override
4447
String get sounds => "声音";
4548
@override
4649
String get pause_resume => "暂停/恢复";

lib/income/donation_dialog.dart

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter/services.dart';
3+
import 'package:overlay_support/overlay_support.dart';
4+
5+
const HONG_BAO = "打开支付宝首页搜“621412820”领红包,领到大红包的小伙伴赶紧使用哦!";
6+
7+
class DonationDialog extends StatelessWidget {
8+
@override
9+
Widget build(BuildContext context) {
10+
return SimpleDialog(
11+
contentPadding:
12+
const EdgeInsets.only(top: 8, left: 8, right: 8, bottom: 4),
13+
children: <Widget>[
14+
SizedBox(width: MediaQuery.of(context).size.width),
15+
Container(
16+
padding: const EdgeInsets.all(16), child: Text("开发不易,赞助一下开发者。")),
17+
_ActionTile(
18+
text: "微信捐赠",
19+
onTap: () async {
20+
await showDialog(
21+
context: context,
22+
builder: (context) => _ReceiptDialog.weChat());
23+
Navigator.pop(context);
24+
},
25+
),
26+
_ActionTile(
27+
text: "支付宝捐赠",
28+
onTap: () async {
29+
await showDialog(
30+
context: context,
31+
builder: (context) => _ReceiptDialog.aliPay());
32+
Navigator.pop(context);
33+
},
34+
),
35+
_ActionTile(
36+
text: "支付宝红包码",
37+
onTap: () async {
38+
await Clipboard.setData(ClipboardData(text: HONG_BAO));
39+
final data = await Clipboard.getData(Clipboard.kTextPlain);
40+
if (data.text == HONG_BAO) {
41+
showSimpleNotification(context, Text("已复制到粘贴板 (≧y≦*)"));
42+
} else {
43+
await showDialog(
44+
context: context,
45+
builder: (context) => _SingleFieldDialog(text: HONG_BAO));
46+
}
47+
Navigator.of(context).pop();
48+
},
49+
),
50+
],
51+
);
52+
}
53+
}
54+
55+
class _SingleFieldDialog extends StatelessWidget {
56+
final String text;
57+
58+
const _SingleFieldDialog({Key key, @required this.text}) : super(key: key);
59+
60+
@override
61+
Widget build(BuildContext context) {
62+
return Dialog(
63+
child: Container(
64+
padding: EdgeInsets.all(16),
65+
child: TextField(
66+
maxLines: 5,
67+
autofocus: true,
68+
controller: TextEditingController(text: text),
69+
),
70+
),
71+
);
72+
}
73+
}
74+
75+
class _ReceiptDialog extends StatelessWidget {
76+
final String image;
77+
78+
const _ReceiptDialog({Key key, this.image}) : super(key: key);
79+
80+
const _ReceiptDialog.weChat() : this(image: "assets/wechat.png");
81+
82+
const _ReceiptDialog.aliPay() : this(image: "assets/alipay.jpg");
83+
84+
static final borderRadius = BorderRadius.circular(5);
85+
86+
@override
87+
Widget build(BuildContext context) {
88+
return Dialog(
89+
shape: RoundedRectangleBorder(borderRadius: borderRadius),
90+
child: ClipRRect(borderRadius: borderRadius, child: Image.asset(image)),
91+
);
92+
}
93+
}
94+
95+
class _ActionTile extends StatelessWidget {
96+
final VoidCallback onTap;
97+
98+
final String text;
99+
100+
const _ActionTile({Key key, @required this.onTap, @required this.text})
101+
: super(key: key);
102+
103+
@override
104+
Widget build(BuildContext context) {
105+
return InkWell(
106+
onTap: onTap,
107+
child: Container(
108+
height: 40,
109+
child: Row(
110+
children: <Widget>[
111+
SizedBox(width: 16),
112+
Text(text, style: TextStyle(fontWeight: FontWeight.bold)),
113+
],
114+
),
115+
),
116+
);
117+
}
118+
}

lib/main.dart

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter_localizations/flutter_localizations.dart';
23
import 'package:tetris/gamer/gamer.dart';
34
import 'package:tetris/generated/i18n.dart';
4-
import 'package:tetris/panel/screen.dart';
5+
import 'package:tetris/income/donation_dialog.dart';
56
import 'package:tetris/panel/controller.dart';
6-
import 'package:flutter_localizations/flutter_localizations.dart';
7+
import 'package:tetris/panel/screen.dart';
78

89
void main() {
910
_disableDebugPrint();
@@ -23,6 +24,8 @@ void _disableDebugPrint() {
2324
}
2425
}
2526

27+
final RouteObserver<ModalRoute> routeObserver = RouteObserver<ModalRoute>();
28+
2629
class MyApp extends StatelessWidget {
2730
// This widget is the root of your application.
2831
@override
@@ -34,6 +37,7 @@ class MyApp extends StatelessWidget {
3437
GlobalMaterialLocalizations.delegate,
3538
GlobalWidgetsLocalizations.delegate
3639
],
40+
navigatorObservers: [routeObserver],
3741
supportedLocales: S.delegate.supportedLocales,
3842
theme: ThemeData(
3943
primarySwatch: Colors.blue,
@@ -60,6 +64,18 @@ class _HomePage extends StatelessWidget {
6064
padding: MediaQuery.of(context).padding,
6165
child: Column(
6266
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+
),
6379
Spacer(),
6480
Container(
6581
decoration: BoxDecoration(
@@ -88,7 +104,7 @@ class _HomePage extends StatelessWidget {
88104
),
89105
),
90106
),
91-
Spacer(),
107+
Spacer(flex: 2),
92108
GameController(),
93109
],
94110
),

pubspec.yaml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ dependencies:
1717
sdk: flutter
1818
flutter_localizations:
1919
sdk: flutter
20-
# The following adds the Cupertino Icons font to your application.
21-
# Use with the CupertinoIcons class for iOS style icons.
22-
cupertino_icons: ^0.1.2
20+
overlay_support:
21+
git:
22+
url: git://github.com/boyan01/quiet-flutter.git
23+
path: overlay_support
2324
audioplayers: ^0.8.0
2425

2526
dev_dependencies:
@@ -32,15 +33,13 @@ dev_dependencies:
3233
# The following section is specific to Flutter.
3334
flutter:
3435

35-
# The following line ensures that the Material Icons font is
36-
# included with your application, so that you can use the icons in
37-
# the material Icons class.
3836
uses-material-design: true
3937

40-
# To add assets to your application, add an assets section, like this:
4138
assets:
42-
- assets/material.png
43-
- assets/music.mp3
39+
- assets/material.png
40+
- assets/music.mp3
41+
- assets/alipay.jpg
42+
- assets/wechat.png
4443

4544
# An image asset can refer to one or more resolution-specific "variants", see
4645
# https://flutter.io/assets-and-images/#resolution-aware.

res/values/strings_en.arb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"points": "Points",
66
"cleans": "Cleans",
77
"level": "Level",
8-
"next": "Next"
8+
"next": "Next",
9+
"reward": "Reward"
910
}

res/values/strings_zh_CN.arb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"points": "分数",
66
"cleans": "消除",
77
"level": "级别",
8-
"next": "下一个"
8+
"next": "下一个",
9+
"reward": "赞赏"
910
}

0 commit comments

Comments
 (0)