@@ -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?\n Tad 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}
0 commit comments