Skip to content

Commit 9f4032b

Browse files
authored
Merge pull request #14 from FrenkyDema/task/fix-action-buttons
Fix ActionButtons
2 parents 1e292ed + 7236ca7 commit 9f4032b

File tree

8 files changed

+719
-160
lines changed

8 files changed

+719
-160
lines changed

example/lib/main.dart

Lines changed: 104 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -78,34 +78,90 @@ class _HomePageState extends State<HomePage> {
7878

7979
// Increment/Decrement Page
8080
Widget _buildIncrementDecrementPage(BuildContext context) {
81-
int quantity = 1;
82-
8381
return StatefulBuilder(
8482
builder: (context, setState) {
83+
int quantity1 = 1;
84+
int quantity2 = 5;
85+
int quantity3 = 8;
86+
8587
return PaddedChildrenList(
8688
children: [
8789
Text(
8890
'Increment/Decrement Widget',
8991
style: Theme.of(context).textTheme.titleLarge,
9092
),
91-
IncrementDecrementWidget(
92-
quantity: quantity,
93-
maxQuantity: 10,
94-
minValue: 1,
95-
onIncrement: () {
96-
setState(() {
97-
if (quantity < 10) quantity++;
98-
});
93+
const SizedBox(height: 16),
94+
95+
// Flat Example
96+
StatefulBuilder(
97+
builder: (context, setState) {
98+
return IncrementDecrementWidget.flat(
99+
quantity: quantity1,
100+
maxQuantity: 10,
101+
minValue: 1,
102+
onIncrement: () {
103+
setState(() {
104+
if (quantity1 < 10) quantity1++;
105+
});
106+
},
107+
onDecrement: () {
108+
setState(() {
109+
if (quantity1 > 1) quantity1--;
110+
});
111+
},
112+
backgroundColor: Colors.grey[200],
113+
iconColor: Colors.blue,
114+
);
99115
},
100-
onDecrement: () {
101-
setState(() {
102-
if (quantity > 1) quantity--;
103-
});
116+
),
117+
118+
const SizedBox(height: 16),
119+
120+
// Raised Example
121+
StatefulBuilder(
122+
builder: (context, setState) {
123+
return IncrementDecrementWidget.raised(
124+
quantity: quantity2,
125+
maxQuantity: 15,
126+
minValue: 0,
127+
onIncrement: () {
128+
setState(() {
129+
if (quantity2 < 15) quantity2++;
130+
});
131+
},
132+
onDecrement: () {
133+
setState(() {
134+
if (quantity2 > 0) quantity2--;
135+
});
136+
},
137+
backgroundColor: Colors.lightGreen[100],
138+
iconColor: Colors.green,
139+
);
140+
},
141+
),
142+
143+
const SizedBox(height: 16),
144+
145+
// Minimal Example
146+
StatefulBuilder(
147+
builder: (context, setState) {
148+
return IncrementDecrementWidget.minimal(
149+
quantity: quantity3,
150+
maxQuantity: 20,
151+
minValue: 5,
152+
onIncrement: () {
153+
setState(() {
154+
if (quantity3 < 20) quantity3++;
155+
});
156+
},
157+
onDecrement: () {
158+
setState(() {
159+
if (quantity3 > 5) quantity3--;
160+
});
161+
},
162+
iconColor: Colors.red,
163+
);
104164
},
105-
backgroundColor: Colors.grey[200],
106-
iconColor: Colors.blue,
107-
elevation: 4.0,
108-
margin: const EdgeInsets.all(8.0),
109165
),
110166
],
111167
);
@@ -122,10 +178,12 @@ class _HomePageState extends State<HomePage> {
122178
return PaddedChildrenList(
123179
children: [
124180
Text(
125-
'Custom Action Button',
181+
'Custom Action Buttons',
126182
style: Theme.of(context).textTheme.titleLarge,
127183
),
128-
CustomActionButton(
184+
const SizedBox(height: 16),
185+
// Raised Button Example
186+
CustomActionButton.raised(
129187
onPressed: () {
130188
setState(() {
131189
counter++;
@@ -135,9 +193,34 @@ class _HomePageState extends State<HomePage> {
135193
borderColor: Colors.blueAccent,
136194
elevation: 4.0,
137195
borderRadius: 8.0,
138-
child: Text('Custom Action Button ($counter)',
196+
child: Text('Raised Button ($counter)',
139197
style: const TextStyle(color: Colors.white)),
140198
),
199+
const SizedBox(height: 16),
200+
// Flat Button Example
201+
CustomActionButton.flat(
202+
onPressed: () {
203+
setState(() {
204+
counter++;
205+
});
206+
},
207+
backgroundColor: Colors.green,
208+
borderColor: Colors.transparent,
209+
borderRadius: 8.0,
210+
child: Text('Flat Button ($counter)',
211+
style: const TextStyle(color: Colors.white)),
212+
),
213+
const SizedBox(height: 16),
214+
// Minimal Button Example
215+
CustomActionButton.minimal(
216+
onPressed: () {
217+
setState(() {
218+
counter++;
219+
});
220+
},
221+
child: Text('Minimal Button ($counter)',
222+
style: const TextStyle(color: Colors.black)),
223+
),
141224
],
142225
);
143226
},

lib/risto_widgets.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
library risto_widgets;
22

3+
export 'widgets/buttons/action_wrapper.dart';
34
export 'widgets/buttons/custom_action_button.dart';
5+
export 'widgets/buttons/expandable_list_tile_button.dart';
46
export 'widgets/buttons/list_tile_button.dart';
5-
export 'widgets/navigation/custom_bottom_navbar.dart';
67
export 'widgets/input/increment_decrement_widget.dart';
7-
export 'widgets/sheets/open_custom_sheet.dart';
88
export 'widgets/layouts/padded_widgets.dart';
9-
export 'widgets/buttons/expandable_list_tile_button.dart';
9+
export 'widgets/navigation/custom_bottom_navbar.dart';
10+
export 'widgets/sheets/open_custom_sheet.dart';
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import 'package:flutter/material.dart';
2+
3+
class ActionButtonWrapper extends StatelessWidget {
4+
final EdgeInsetsGeometry _margin;
5+
final double _height;
6+
final double _width;
7+
final Widget child;
8+
final Color? backgroundColor;
9+
final BorderRadius? borderRadius;
10+
11+
ActionButtonWrapper({
12+
super.key,
13+
EdgeInsetsGeometry? margin,
14+
double paddingValue = 16.0, // Default value
15+
double? height,
16+
double? width,
17+
required this.child,
18+
this.backgroundColor,
19+
this.borderRadius,
20+
}) : _margin = margin ??
21+
EdgeInsets.only(
22+
bottom: 8,
23+
right: paddingValue,
24+
left: paddingValue,
25+
),
26+
_height = height ?? 60,
27+
_width = width ?? double.infinity;
28+
29+
@override
30+
Widget build(BuildContext context) {
31+
return Container(
32+
margin: _margin,
33+
width: _width,
34+
height: _height,
35+
decoration: BoxDecoration(
36+
color: backgroundColor ?? Colors.transparent,
37+
borderRadius: borderRadius ?? BorderRadius.circular(10),
38+
),
39+
child: child,
40+
);
41+
}
42+
}

0 commit comments

Comments
 (0)