forked from TheAlphamerc/flutter_twitter_clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomLoader.dart
104 lines (94 loc) · 2.47 KB
/
customLoader.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
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class CustomLoader {
static CustomLoader? _customLoader;
CustomLoader._createObject();
factory CustomLoader() {
if (_customLoader != null) {
return _customLoader!;
} else {
_customLoader = CustomLoader._createObject();
return _customLoader!;
}
}
OverlayState? _overlayState;
OverlayEntry? _overlayEntry;
_buildLoader() {
_overlayEntry = OverlayEntry(
builder: (context) {
return SizedBox(
height: double.infinity,
width: double.infinity,
child: buildLoader(context));
},
);
}
showLoader(context) {
_overlayState = Overlay.of(context);
_buildLoader();
_overlayState!.insert(_overlayEntry!);
}
hideLoader() {
try {
_overlayEntry?.remove();
_overlayEntry = null;
} catch (e) {
print("Exception:: $e");
}
}
buildLoader(BuildContext context, {Color? backgroundColor}) {
backgroundColor ??= const Color(0xffa8a8a8).withOpacity(.5);
var height = 150.0;
return CustomScreenLoader(
height: height,
width: height,
backgroundColor: backgroundColor,
);
}
}
class CustomScreenLoader extends StatelessWidget {
final Color backgroundColor;
final double height;
final double width;
const CustomScreenLoader(
{Key? key,
this.backgroundColor = const Color(0xfff8f8f8),
this.height = 30,
this.width = 30})
: super(key: key);
@override
Widget build(BuildContext context) {
return Container(
color: backgroundColor,
child: Container(
height: height,
width: height,
alignment: Alignment.center,
child: Container(
padding: const EdgeInsets.all(50),
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(10))),
child: Stack(
alignment: Alignment.center,
children: <Widget>[
Platform.isIOS
? const CupertinoActivityIndicator(
radius: 35,
)
: const CircularProgressIndicator(
strokeWidth: 2,
),
Image.asset(
'assets/images/icon-480.png',
height: 30,
width: 30,
)
],
),
),
),
);
}
}