-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstepper.dart
167 lines (152 loc) · 4.71 KB
/
stepper.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Post has been taken from Ranga Reddy- https://dev.to/irangareddy/custom-stepper-in-flutter-40o8
//this is stepper.dart
What is a Stepper?
A stepper is a two-buttons used to increase or decrease an incremental value.
By default, one button of a stepper displays a plus symbol, and the other displays a minus symbol.
These symbols can be replaced with custom images if desired.
class StepperScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: kPrimaryColor,
title: Text("Custom Stepper"),
centerTitle: false,
),
body: SafeArea(
child: Center(
child: Container(
height: 300,
width: 200,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8.0),
boxShadow: [
BoxShadow(
color: kShadowColor,
offset: Offset(0, 20),
blurRadius: 30.0),
]
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.04),
borderRadius: BorderRadius.circular(8.0),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Image.asset('assets/images/fruit.png',fit: BoxFit.fitWidth,),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 8.0,left: 8.0),
child: Text('Juicy Strawberry',style: TextStyle(
color: Colors.black,
fontSize: 18.0,
),),
),
Padding(
padding: const EdgeInsets.only(top: 8.0,left: 8.0),
child: Row(
children: [
Text('\$20.40',style: TextStyle(
color: Colors.black,
fontSize: 15.0,
fontWeight: FontWeight.bold,
),),
Spacer(),
CustomStepper()
],
),
),
],
),
)),
),
);
}
}
class CustomStepper extends StatefulWidget {
CustomStepper({
@required this.lowerLimit,
@required this.upperLimit,
@required this.stepValue,
@required this.iconSize,
@required this.value,
});
final int lowerLimit;
final int upperLimit;
final int stepValue;
final double iconSize;
int value;
@override
_CustomStepperState createState() => _CustomStepperState();
}
class _CustomStepperState extends State<CustomStepper> {
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RoundedIconButton(
icon: Icons.remove,
iconSize: widget.iconSize,
onPress: () {
setState(() {
widget.value =
widget.value == widget.lowerLimit ? widget.lowerLimit : widget.value -= widget.stepValue;
});
},
),
Container(
width: widget.iconSize,
child: Text(
'${widget.value}',
style: TextStyle(
fontSize: widget.iconSize * 0.8,
),
textAlign: TextAlign.center,
),
),
RoundedIconButton(
icon: Icons.add,
iconSize: widget.iconSize,
onPress: () {
setState(() {
widget.value =
widget.value == widget.upperLimit ? widget.upperLimit : widget.value += widget.stepValue;
});
},
),
],
);
}
}
class RoundedIconButton extends StatelessWidget {
RoundedIconButton({@required this.icon, @required this.onPress, @required this.iconSize});
final IconData icon;
final Function onPress;
final double iconSize;
@override
Widget build(BuildContext context) {
return RawMaterialButton(
constraints: BoxConstraints.tightFor(width: iconSize, height: iconSize),
elevation: 6.0,
onPressed: onPress,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(iconSize*0.2)),
fillColor: Color(0xFF65A34A),
child: Icon(
icon,
color: Colors.white,
size: iconSize * 0.8,
),
);
}
}