-
Notifications
You must be signed in to change notification settings - Fork 64
/
07. twitter-new-data-indicator.dart
133 lines (122 loc) · 4.3 KB
/
07. twitter-new-data-indicator.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
class NewDataIndicatorNotifier extends ChangeNotifier {
bool _receivedNewData = false;
bool get receivedNewData => _receivedNewData;
List<String> baseData = [
"Lorem Ipsum ",
"is simply dummy",
"text of the printing",
"and typesetting industry",
"when an unknown printer",
"type specimen book"
];
List<String> tempDataList = [];
void fillTempList({required String data}) {
tempDataList.add(data);
notifyListeners();
}
void fillBaseList() {
baseData.addAll(tempDataList);
tempDataList.clear();
notifyListeners();
}
setReceivedNewData() {
_receivedNewData = true;
notifyListeners();
}
}
class TwitterPullToRefreshView extends StatelessWidget {
const TwitterPullToRefreshView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final ScrollController scrollController = ScrollController();
NewDataIndicatorNotifier newDataIndicatorNotifier(
{required bool renderUI}) =>
Provider.of<NewDataIndicatorNotifier>(context, listen: renderUI);
List<String> data = newDataIndicatorNotifier(renderUI: true).baseData;
bool hasNewData =
newDataIndicatorNotifier(renderUI: true).tempDataList.isNotEmpty;
void scrollToTop() {
scrollController.jumpTo(scrollController.position.maxScrollExtent);
}
Widget newDataNotificationBlock() {
return Padding(
padding: const EdgeInsets.only(top: 10),
child: AnimatedOpacity(
curve: Curves.easeInCubic,
duration: const Duration(milliseconds: 500),
opacity: hasNewData ? 1 : 0,
child: Align(
alignment: Alignment.topCenter,
child: CustomRoundedIconButton(
height: 5,
iconData: Icons.arrow_drop_down_circle,
width: 35,
radius: 50,
backgroundColor: KConstantColors.blueColor,
onTap: () {
scrollToTop();
newDataIndicatorNotifier(renderUI: false).fillBaseList();
},
label: "New posts"),
),
),
);
}
return Sizer(builder: (context, origentation, _) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
floatingActionButton: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
CustomRoundedButton(
width: 40,
backgroundColor: KConstantColors.blueColor,
onTap: () {
DateTime timeStamp = DateTime.now();
newDataIndicatorNotifier(renderUI: false)
.fillTempList(data: "New data : $timeStamp");
},
label: "Add more data"),
],
),
appBar: AppBar(
backgroundColor: KConstantColors.blueColor,
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(FontAwesomeIcons.twitter),
hSizedBox2,
Text("Twitter New Data Indicator",
style: KCustomTextStyle.kBold(context, 16))
],
)),
backgroundColor: KConstantColors.bgColor,
body: Stack(
children: [
ListView.builder(
reverse: true,
controller: scrollController,
shrinkWrap: true,
itemCount: data.length,
itemBuilder: (BuildContext context, int index) {
return Card(
color: KConstantColors.bgColorFaint,
elevation: 0.4,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ListTile(
tileColor: KConstantColors.bgColorFaint,
title: Text(data[index],
style: KCustomTextStyle.kMedium(context, 10))),
),
);
},
),
Positioned(child: newDataNotificationBlock())
],
)),
);
});
}
}