-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.dart
169 lines (155 loc) · 4.96 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
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
168
169
import 'package:flutter/material.dart';
import 'package:hidable/hidable.dart';
void main() => runApp(const App());
class App extends StatelessWidget {
const App({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: Example(),
);
}
}
class Example extends StatefulWidget {
const Example({Key? key}) : super(key: key);
@override
State<Example> createState() => _ExampleState();
}
class _ExampleState extends State<Example> {
final colorsPath = [Colors.green, Colors.orangeAccent, Colors.orange, Colors.red];
int index = 0;
// Create scroll controller that will be given to scrollable widget and hidable.
final ScrollController scrollController = ScrollController();
@override
Widget build(BuildContext context) {
return Scaffold(
/// We've wrapped [AppBar] with [Hidable].
/// So, now, our [AppBar] supports scroll to hide feature.
appBar: Hidable(
controller: scrollController,
child: AppBar(
backgroundColor: colorsPath[index].withOpacity(.6),
title: const Text('Hidable'),
),
),
/// Scrollable widget of main widget
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 10),
child: ListView.separated(
/// scrollController should be given here, to scrollable widget.
/// and same controller must to be given hidable.
controller: scrollController,
itemCount: 15,
itemBuilder: (_, i) => _ListItem(),
separatorBuilder: (_, __) => const SizedBox(height: 10),
),
),
/// We've wrapped [BottomNavigationBar] with [Hidable].
/// So, now, our [BottomNavigationBar] supports scroll to hide feature.
bottomNavigationBar: Hidable(
controller: scrollController,
enableOpacityAnimation: true, // As default it's true
child: BottomNavigationBar(
currentIndex: index,
onTap: (i) => setState(() => index = i),
items: bottomBarItems(),
),
),
/// We've wrapped [FloatingActionButton] with [Hidable].
/// So, now, our [FloatingActionButton] supports scroll to hide feature.
floatingActionButton: Hidable(
controller: scrollController,
child: Align(
alignment: Alignment.centerRight,
child: FloatingActionButton(
child: const Icon(Icons.label),
backgroundColor: colorsPath[index].withOpacity(.8),
onPressed: () {
// Do something ...
},
),
),
),
);
}
List<BottomNavigationBarItem> bottomBarItems() {
return [
BottomNavigationBarItem(
label: 'Home',
icon: const Icon(Icons.home, color: Colors.white),
backgroundColor: colorsPath[0].withOpacity(.6),
),
BottomNavigationBarItem(
label: 'Favorites',
icon: const Icon(Icons.favorite, color: Colors.white),
backgroundColor: colorsPath[1].withOpacity(.6),
),
BottomNavigationBarItem(
label: 'Profile',
icon: const Icon(Icons.person, color: Colors.white),
backgroundColor: colorsPath[2].withOpacity(.6),
),
BottomNavigationBarItem(
label: 'Settings',
icon: const Icon(Icons.settings, color: Colors.white),
backgroundColor: colorsPath[3].withOpacity(.6),
),
];
}
}
class _ListItem extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListTile(
leading: Container(
height: 50,
width: 50,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.grey.withOpacity(.4),
),
),
title: Align(
alignment: Alignment.topLeft,
child: Column(
children: [
Container(
height: 15,
width: MediaQuery.of(context).size.width / 2,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
color: Colors.grey.withOpacity(.5),
),
),
const SizedBox(height: 10),
],
),
),
subtitle: Align(
alignment: Alignment.bottomLeft,
child: Column(
children: [
Container(
height: 10,
width: MediaQuery.of(context).size.width / 1.2,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
color: Colors.grey.withOpacity(.3),
),
),
const SizedBox(height: 5),
Container(
height: 10,
width: MediaQuery.of(context).size.width / 1.2,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
color: Colors.grey.withOpacity(.3),
),
),
],
),
),
);
}
}