-
Notifications
You must be signed in to change notification settings - Fork 64
/
30.flutter_ui_utils.dart
108 lines (98 loc) · 3.51 KB
/
30.flutter_ui_utils.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
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:ig_posts/features/1.flutter_frost_glass.view.dart';
import 'package:ig_posts/features/5.flutter_swiggy_button.dart';
import 'package:provider/provider.dart';
class OnScrollNotifier extends ChangeNotifier {
bool _isViewScrolling = false;
bool get isViewScrolling => _isViewScrolling;
void setOnViewScrolling({required bool isScrolling}) {
_isViewScrolling = isScrolling;
notifyListeners();
}
}
class FlutterOnScrollContainerFab extends StatefulWidget {
const FlutterOnScrollContainerFab({super.key});
@override
State<FlutterOnScrollContainerFab> createState() =>
_FlutterOnScrollContainerFabState();
}
class _FlutterOnScrollContainerFabState
extends State<FlutterOnScrollContainerFab> {
OnScrollNotifier onScrollNotifier({required bool renderUI}) =>
Provider.of<OnScrollNotifier>(context, listen: renderUI);
ScrollController scrollController = new ScrollController();
@override
void initState() {
scrollController.addListener(() {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
if (scrollController.position.userScrollDirection ==
ScrollDirection.forward) {
onScrollNotifier(renderUI: false)
.setOnViewScrolling(isScrolling: false);
} else {
onScrollNotifier(renderUI: false)
.setOnViewScrolling(isScrolling: true);
}
});
});
super.initState();
}
@override
Widget build(BuildContext context) {
bool isScrolling = onScrollNotifier(renderUI: true).isViewScrolling;
Widget customFab() {
if (!isScrolling) {
return AnimatedContainer(
curve: Curves.linearToEaseOut,
duration: Duration(milliseconds: 100),
height: 50,
width: 300,
child: Center(child: Text("Add your widget here", style: boldText())),
decoration: BoxDecoration(
color: bgColorFaint, borderRadius: BorderRadius.circular(25)),
);
} else {
return AnimatedContainer(
duration: Duration(milliseconds: 500),
height: 50,
width: 150,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(Icons.comment, color: Colors.white),
SizedBox(width: 10),
Text("12", style: regulerText),
SizedBox(width: 30),
Icon(Icons.thumb_up, color: Colors.white),
SizedBox(width: 10),
Text("07", style: regulerText),
],
),
decoration: BoxDecoration(
color: bgColorFaint, borderRadius: BorderRadius.circular(25)),
);
}
}
return Scaffold(
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: customFab(),
backgroundColor: bgColor,
appBar: AppBar(
title: Text("Flutter FAB animation", style: boldText()),
backgroundColor: bgColorFaint),
body: ListView.builder(
controller: scrollController,
shrinkWrap: true,
itemCount: 50,
itemBuilder: (BuildContext context, int index) {
return ListTile(
leading: CircleAvatar(backgroundColor: Colors.orangeAccent),
subtitle: Text("Some demo data", style: regulerText),
title: Text("Item no : $index", style: boldText()));
},
),
);
}
}