-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dart
57 lines (51 loc) · 1.45 KB
/
main.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
import 'package:example/my_cool_widget.dart';
import 'package:flutter/material.dart';
import 'package:efficient_indexed_stack/efficient_indexed_stack.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
int activeIndex = 0;
final itemCount = 30;
int get maxIndex => itemCount - 1;
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: Text('Active index : $activeIndex'),
actions: [
IconButton(
icon: const Icon(Icons.arrow_left_rounded),
onPressed: () => setState(() {
activeIndex = (activeIndex - 1).clamp(0, maxIndex);
}),
),
const SizedBox(width: 24),
IconButton(
icon: const Icon(Icons.arrow_right_rounded),
onPressed: () => setState(() {
activeIndex = (activeIndex + 1).clamp(0, maxIndex);
}),
),
],
),
body: EfficientIndexedStack(
index: activeIndex,
itemCount: itemCount,
keepAliveDistance: 3,
itemBuilder: (_, index) => MyCoolWidget(
index,
key: GlobalKey(),
),
),
),
);
}
}