-
-
Notifications
You must be signed in to change notification settings - Fork 630
/
cupertino_page.dart
143 lines (137 loc) · 4.54 KB
/
cupertino_page.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
import 'package:easy_refresh/easy_refresh.dart';
import 'package:example/widget/skeleton_item.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class CupertinoIndicatorPage extends StatefulWidget {
const CupertinoIndicatorPage({super.key});
@override
State<CupertinoIndicatorPage> createState() => _CupertinoIndicatorPageState();
}
class _CupertinoIndicatorPageState extends State<CupertinoIndicatorPage> {
Axis _scrollDirection = Axis.vertical;
int _count = 10;
late EasyRefreshController _controller;
@override
void initState() {
super.initState();
_controller = EasyRefreshController(
controlFinishRefresh: true,
controlFinishLoad: true,
);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final themeData = Theme.of(context);
return Material(
color: Colors.transparent,
child: CupertinoPageScaffold(
navigationBar: _scrollDirection == Axis.vertical
? null
: CupertinoNavigationBar(
middle: Text(
'iOS Cupertino',
style: TextStyle(
color: themeData.textTheme.titleMedium?.color,
),
),
trailing: IconButton(
iconSize: 24,
onPressed: () {
setState(() {
_scrollDirection = _scrollDirection == Axis.horizontal
? Axis.vertical
: Axis.horizontal;
});
},
icon: Icon(_scrollDirection == Axis.horizontal
? Icons.horizontal_distribute
: Icons.vertical_distribute),
),
),
child: SafeArea(
top: _scrollDirection == Axis.horizontal,
bottom: false,
left: false,
right: false,
child: EasyRefresh(
controller: _controller,
header: const CupertinoHeader(
position: IndicatorPosition.locator,
safeArea: false,
),
footer: const CupertinoFooter(
position: IndicatorPosition.locator,
),
onRefresh: () async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return;
}
setState(() {
_count = 10;
});
_controller.finishRefresh();
_controller.resetFooter();
},
onLoad: () async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return;
}
setState(() {
_count += 5;
});
_controller.finishLoad(_count >= 20
? IndicatorResult.noMore
: IndicatorResult.success);
},
child: CustomScrollView(
scrollDirection: _scrollDirection,
slivers: [
if (_scrollDirection == Axis.vertical)
CupertinoSliverNavigationBar(
largeTitle: Text(
'iOS Cupertino',
style: TextStyle(
color: themeData.textTheme.titleMedium?.color,
),
),
trailing: IconButton(
iconSize: 24,
onPressed: () {
setState(() {
_scrollDirection = _scrollDirection == Axis.horizontal
? Axis.vertical
: Axis.horizontal;
});
},
icon: Icon(_scrollDirection == Axis.horizontal
? Icons.horizontal_distribute
: Icons.vertical_distribute),
),
),
const HeaderLocator.sliver(),
SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
return SkeletonItem(
direction: _scrollDirection,
);
},
childCount: _count,
),
),
const FooterLocator.sliver(),
],
),
),
),
),
);
}
}