forked from darioielardi/flutter_speed_dial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dart
156 lines (142 loc) · 4.88 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
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
void main() =>
runApp(MaterialApp(home: MyApp(), title: 'Flutter Speed Dial Example'));
class MyApp extends StatefulWidget {
@override
MyAppState createState() => MyAppState();
}
class MyAppState extends State<MyApp> with TickerProviderStateMixin {
ScrollController scrollController;
bool dialVisible = true;
@override
void initState() {
super.initState();
scrollController = ScrollController()
..addListener(() {
setDialVisible(scrollController.position.userScrollDirection ==
ScrollDirection.forward);
});
}
void setDialVisible(bool value) {
setState(() {
dialVisible = value;
});
}
Widget get _speedDial => SpeedDial(
icon: Icons.more_vert,
useRotationAnimation: false,
iconTheme: const IconThemeData(size: 30),
activeBackgroundColor: Colors.blue.shade900,
activeForegroundColor: Colors.white,
buttonPadding: EdgeInsets.only(top: 4),
overlayOpacity: 0,
curve: Curves.bounceIn,
backgroundColor: Colors.white,
marginEnd: 0,
foregroundColor: Theme.of(context).primaryColorDark,
buttonSize: 30,
children: <SpeedDialChild>[
SpeedDialChild(
child: Icon(Icons.share, size: 20),
backgroundColor: Colors.white,
foregroundColor: Theme.of(context).primaryColorDark,
),
SpeedDialChild(
child: Icon(Icons.favorite, size: 20),
backgroundColor: Colors.white,
foregroundColor: Theme.of(context).primaryColorDark,
)
],
);
Widget buildBody() {
return ListView.builder(
controller: scrollController,
itemCount: 30,
itemBuilder: (ctx, i) => ListTile(
title: Text('Item $i'),
trailing: Container(width: 50, height: 50, child: _speedDial),
),
);
}
SpeedDial buildSpeedDial() {
return SpeedDial(
/// both default to 16
marginEnd: 24,
marginBottom: 16,
// animatedIcon: AnimatedIcons.menu_close,
// animatedIconTheme: IconThemeData(size: 22.0),
/// This is ignored if animatedIcon is non null
icon: Icons.add,
activeIcon: Icons.remove,
// iconTheme: IconThemeData(color: Colors.grey[50], size: 30),
/// The label of the main button.
// label: Text("Open Speed Dial"),
/// The active label of the main button, Defaults to label if not specified.
// activeLabel: Text("Close Speed Dial"),
/// Transition Builder between label and activeLabel, defaults to FadeTransition.
// labelTransitionBuilder: (widget, animation) => ScaleTransition(scale: animation,child: widget),
/// The below button size defaults to 56 itself, its the FAB size + It also affects relative padding and other elements
buttonSize: 56.0,
visible: true,
/// If true user is forced to close dial manually
/// by tapping main button and overlay is not rendered.
closeManually: false,
curve: Curves.bounceIn,
overlayColor: Colors.black,
overlayOpacity: 0.5,
onOpen: () => print('OPENING DIAL'),
onClose: () => print('DIAL CLOSED'),
tooltip: 'Speed Dial',
heroTag: 'speed-dial-hero-tag',
backgroundColor: Colors.white,
foregroundColor: Colors.black,
elevation: 8.0,
shape: CircleBorder(),
// orientation: SpeedDialOrientation.Up,
// childMarginBottom: 2,
// childMarginTop: 2,
gradientBoxShape: BoxShape.circle,
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Colors.black, Colors.white],
),
children: [
SpeedDialChild(
child: Icon(Icons.accessibility),
backgroundColor: Colors.red,
label: 'First',
labelStyle: TextStyle(fontSize: 18.0),
onTap: () => print('FIRST CHILD'),
onLongPress: () => print('FIRST CHILD LONG PRESS'),
),
SpeedDialChild(
child: Icon(Icons.brush),
backgroundColor: Colors.blue,
label: 'Second',
labelStyle: TextStyle(fontSize: 18.0),
onTap: () => print('SECOND CHILD'),
onLongPress: () => print('SECOND CHILD LONG PRESS'),
),
SpeedDialChild(
child: Icon(Icons.keyboard_voice),
backgroundColor: Colors.green,
label: 'Third',
labelStyle: TextStyle(fontSize: 18.0),
onTap: () => print('THIRD CHILD'),
onLongPress: () => print('THIRD CHILD LONG PRESS'),
),
],
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Flutter Speed Dial')),
body: buildBody(),
floatingActionButton: buildSpeedDial(),
);
}
}