Skip to content

Commit b13cd99

Browse files
committed
adjust image size and refactor code
1 parent 626a51e commit b13cd99

File tree

7 files changed

+71
-111
lines changed

7 files changed

+71
-111
lines changed

assets/heart.jpg

-1.98 MB
Loading

assets/rose.jpg

-173 KB
Loading

lib/app.dart

Lines changed: 0 additions & 19 deletions
This file was deleted.

lib/main.dart

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
import 'package:flutter/material.dart';
22

3-
import 'app.dart';
3+
import 'pages/home_page.dart';
44

55
void main() {
66
runApp(const MyApp());
77
}
8+
9+
class MyApp extends StatelessWidget {
10+
const MyApp({Key? key}) : super(key: key);
11+
12+
@override
13+
Widget build(BuildContext context) {
14+
return MaterialApp(
15+
debugShowCheckedModeBanner: false,
16+
title: 'Love Spring 🌸 💖',
17+
theme: ThemeData(
18+
primarySwatch: Colors.blue,
19+
),
20+
home: const HomePage(),
21+
);
22+
}
23+
}

lib/pages/home_page.dart

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ class _HomePageState extends State<HomePage> {
2828
constraints: BoxConstraints.expand(),
2929
decoration: const BoxDecoration(
3030
image: DecorationImage(
31-
image: AssetImage("assets/rose.jpg"), fit: BoxFit.cover),
31+
image: AssetImage("assets/rose.jpg"),
32+
fit: BoxFit.cover,
33+
),
3234
),
3335
child: Stack(
3436
children: [
@@ -37,39 +39,32 @@ class _HomePageState extends State<HomePage> {
3739
const Expanded(
3840
child: Align(
3941
alignment: Alignment(0, 0.5),
40-
child: Text('Spring 🌸 Do you love me?, Tad always love you',
41-
style: TextStyle(
42-
fontSize: 25,
43-
fontWeight: FontWeight.w500,
44-
color: Colors.white,
45-
)),
42+
child: Text(
43+
'Spring 🌸 Do you love me?\nTad always loves you babe 🥰😊',
44+
style: TextStyle(
45+
fontSize: 25,
46+
fontWeight: FontWeight.w500,
47+
color: Colors.white,
48+
),
49+
textAlign: TextAlign.center,
50+
),
4651
),
4752
),
4853
Expanded(
4954
child: Row(
5055
mainAxisAlignment: MainAxisAlignment.spaceAround,
5156
children: [
52-
ElevatedButton(
53-
style: ElevatedButton.styleFrom(
54-
backgroundColor: Colors.teal,
55-
shape: RoundedRectangleBorder(
56-
borderRadius: BorderRadius.circular(18.0),
57-
side: BorderSide(color: Colors.teal),
58-
),
59-
padding: const EdgeInsets.only(
60-
top: 20, bottom: 20, right: 30, left: 30),
61-
),
62-
onHover: (_isHovered) {
63-
setState(() {
64-
_isHovered = !_isHovered;
65-
_changeNoBtnPosition();
66-
});
67-
},
57+
_askButton(
58+
color: Colors.teal,
59+
textButton: 'Yes',
6860
onPressed: () {
69-
Navigator.of(context).push(MaterialPageRoute(
70-
builder: (context) => SuccessPage()));
61+
Navigator.of(context).push(
62+
MaterialPageRoute(
63+
builder: (context) => SuccessPage(),
64+
),
65+
);
7166
},
72-
child: const Text('Yes'),
67+
onHover: (_) => _changeNoBtnPosition(),
7368
),
7469
Visibility(
7570
maintainState: true,
@@ -80,19 +75,8 @@ class _HomePageState extends State<HomePage> {
8075
_showingInitialPositionNoBtn = false;
8176
});
8277
},
83-
child: ElevatedButton(
84-
style: ElevatedButton.styleFrom(
85-
backgroundColor: Colors.red,
86-
shape: RoundedRectangleBorder(
87-
borderRadius: BorderRadius.circular(18.0),
88-
side: BorderSide(color: Colors.red),
89-
),
90-
padding: const EdgeInsets.only(
91-
top: 20, bottom: 20, right: 30, left: 30),
92-
),
93-
onPressed: () {},
94-
child: const Text('No'),
95-
),
78+
child:
79+
_askButton(color: Colors.red, textButton: 'No'),
9680
),
9781
),
9882
],
@@ -108,19 +92,8 @@ class _HomePageState extends State<HomePage> {
10892
child: Visibility(
10993
visible: !_showingInitialPositionNoBtn,
11094
child: MouseRegion(
111-
onEnter: (_) => _changeNoBtnPosition(),
112-
child: ElevatedButton(
113-
style: ElevatedButton.styleFrom(
114-
backgroundColor: _randomColor(),
115-
shape: RoundedRectangleBorder(
116-
borderRadius: BorderRadius.circular(18.0)),
117-
padding: const EdgeInsets.only(
118-
top: 20, bottom: 20, right: 30, left: 30),
119-
),
120-
onPressed: () {},
121-
child: const Text('No'),
122-
),
123-
),
95+
onEnter: (_) => _changeNoBtnPosition(),
96+
child: _askButton(color: _randomColor, textButton: 'No')),
12497
),
12598
),
12699
],
@@ -141,7 +114,32 @@ class _HomePageState extends State<HomePage> {
141114
return Offset(dx, dy);
142115
}
143116

144-
Color _randomColor() {
117+
Color get _randomColor {
145118
return Color((Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
146119
}
120+
121+
ElevatedButton _askButton({
122+
required Color color,
123+
VoidCallback? onPressed,
124+
required String textButton,
125+
Function(bool)? onHover,
126+
}) {
127+
return ElevatedButton(
128+
style: ElevatedButton.styleFrom(
129+
backgroundColor: color,
130+
shape:
131+
RoundedRectangleBorder(borderRadius: BorderRadius.circular(18.0)),
132+
padding:
133+
const EdgeInsets.only(top: 20, bottom: 20, right: 30, left: 30),
134+
),
135+
onPressed: onPressed ?? () {},
136+
onHover: onHover,
137+
child: Text(
138+
textButton,
139+
style: TextStyle(
140+
color: Colors.black,
141+
),
142+
),
143+
);
144+
}
147145
}

lib/pages/success_page.dart

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,14 @@ class SuccessPage extends StatelessWidget {
1111
toolbarHeight: 80,
1212
backgroundColor: Colors.transparent,
1313
elevation: 0,
14-
leading: IconButton(
15-
onPressed: () {
16-
Navigator.of(context).pop();
17-
},
18-
icon: Icon(
19-
Icons.arrow_back_ios,
20-
color: Colors.white,
21-
),
22-
),
2314
),
2415
body: Container(
2516
constraints: BoxConstraints.expand(),
2617
decoration: const BoxDecoration(
2718
image: DecorationImage(
28-
image: AssetImage("assets/heart.jpg"), fit: BoxFit.cover),
19+
image: AssetImage("assets/heart.jpg"),
20+
fit: BoxFit.cover,
21+
),
2922
),
3023
child: Align(
3124
alignment: Alignment(0, 0.5),

test/widget_test.dart

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1 @@
1-
// This is a basic Flutter widget test.
2-
//
3-
// To perform an interaction with a widget in your test, use the WidgetTester
4-
// utility that Flutter provides. For example, you can send tap and scroll
5-
// gestures. You can also use WidgetTester to find child widgets in the widget
6-
// tree, read text, and verify that the values of widget properties are correct.
71

8-
import 'package:flutter/material.dart';
9-
import 'package:flutter_test/flutter_test.dart';
10-
import 'package:love_troll_games/app.dart';
11-
12-
void main() {
13-
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
14-
// Build our app and trigger a frame.
15-
await tester.pumpWidget(const MyApp());
16-
17-
// Verify that our counter starts at 0.
18-
expect(find.text('0'), findsOneWidget);
19-
expect(find.text('1'), findsNothing);
20-
21-
// Tap the '+' icon and trigger a frame.
22-
await tester.tap(find.byIcon(Icons.add));
23-
await tester.pump();
24-
25-
// Verify that our counter has incremented.
26-
expect(find.text('0'), findsNothing);
27-
expect(find.text('1'), findsOneWidget);
28-
});
29-
}

0 commit comments

Comments
 (0)