-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathday046_indexed_stack.dart
121 lines (114 loc) · 3.51 KB
/
day046_indexed_stack.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
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
class Day46IndexedStack extends StatefulWidget {
Day46IndexedStack({Key key}) : super(key: key);
@override
_Day46IndexedStackState createState() => _Day46IndexedStackState();
}
class _Day46IndexedStackState extends State<Day46IndexedStack> {
List colorsList = [
Colors.red[800],
Colors.green[800],
Colors.yellow[800],
Colors.blue[800],
Colors.deepOrange[800],
Colors.deepPurple[800],
];
var _index = 0;
inc() {
// ! increment function....
setState(() {
if (_index < colorsList.length - 1) {
_index++;
}
});
}
dec() {
// ! decrement function....
setState(() {
if (_index > 0) {
_index--;
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("IndexedStack"),
actions: <Widget>[
IconButton(
icon: Icon(Icons.help),
onPressed: () async {
const url =
'https://github.com/sanjaysanju618/100-Days-Of-Flutter-Widgets/' +
'blob/master/hundred_days_of_flutter_widget/' +
'lib/day046_indexed_stack.dart';
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
},
)
],
),
body: SafeArea(
child: Center(
child: Stack(
alignment: Alignment.center,
children: <Widget>[
/**
* ? What is IndexedStack....
* ! IndexedStack is the great widget for swap between multiple widgets....
* ! it have all the property as Stack have in addtion [index]....
*/
IndexedStack(
index:
_index, // ! [index] is the property which decides the viewing element...
sizing:
StackFit.expand, // ! [sizing] is same as [fit] of Stack....
alignment: Alignment.center, // ! we can align the stack....
children: <Widget>[
for (Color color in colorsList)
Container(
width: 250,
height: 250,
color:
color, // ! here we pass the colors from list to the conainer....
child: Center(
child: Text(
_index
.toString(), // ! here we print the current index value....
textAlign: TextAlign.center,
style: TextStyle(color: Colors.white, fontSize: 20),
)),
),
],
),
Positioned(
bottom: 1,
left: 1,
child: IconButton(
icon: Icon(Icons.keyboard_arrow_left),
color: Colors.white,
onPressed: () {
dec(); // ! here we decrement the [_index]....
}),
),
Positioned(
bottom: 1,
right: 1,
child: IconButton(
icon: Icon(Icons.keyboard_arrow_right),
color: Colors.white,
onPressed: () {
inc(); // ! here we increment the [_index]....
}),
)
],
),
)),
);
}
}