forked from md-siam/widget_of_the_day
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindexed_stack.dart
55 lines (51 loc) · 1.25 KB
/
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
import 'package:flutter/material.dart';
class MyIndexedStack extends StatefulWidget {
const MyIndexedStack({Key? key}) : super(key: key);
@override
State<MyIndexedStack> createState() => _MyIndexedStackState();
}
class _MyIndexedStackState extends State<MyIndexedStack> {
int index = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Indexed Stack')),
body: Center(
child: IndexedStack(
index: index,
children: [
Container(
width: 200,
height: 200,
color: Colors.red,
),
Container(
width: 200,
height: 200,
color: Colors.blue,
),
Container(
width: 200,
height: 200,
color: Colors.orange,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
if (index == 2) {
setState(() {
index = 0;
});
} else {
setState(() {
index++;
});
}
},
child: const Icon(Icons.next_plan_outlined),
),
);
}
}