Aidra Connect 10.0.2+16
Aidra Connect Mobile Application
Loading...
Searching...
No Matches
custom_scaffold.dart
Go to the documentation of this file.
1import '/core/ui/widgets/custom_appbar.dart';
2import 'package:flutter/material.dart';
3import 'package:flutter_screenutil/flutter_screenutil.dart';
4import 'package:lottie/lottie.dart';
5
6import '../../constants/assets.dart';
7
8class CustomScaffold extends StatefulWidget {
10 super.key,
11 required this.body,
12 this.isLoading = false,
13 this.title,
14 this.actions,
15 this.bottomWidget,
16 this.isLeadingVisible = true,
17 this.backgroundColor,
18 this.onRefresh,
19 this.floating,
20 });
21
22 final Widget body;
23 final bool isLeadingVisible;
24 final bool isLoading;
25 final String? title;
27 final List<Widget>? actions;
28 final Color? backgroundColor;
29 final VoidCallback? onRefresh;
30 final Widget? floating;
31
32 @override
33 State<CustomScaffold> createState() => _CustomScaffoldState();
34}
35
36class _CustomScaffoldState extends State<CustomScaffold> {
37 final ScrollController _scrollController = ScrollController();
38 bool _showShadow = false;
39
40 @override
41 void initState() {
42 super.initState();
43 _scrollController.addListener(_onScroll);
44 }
45
46 @override
47 void dispose() {
48 _scrollController.removeListener(_onScroll);
49 _scrollController.dispose();
50 super.dispose();
51 }
52
53 void _onScroll() {
54 if (_scrollController.offset > 0 && !_showShadow) {
55 setState(() => _showShadow = true);
56 } else if (_scrollController.offset <= 0 && _showShadow) {
57 setState(() => _showShadow = false);
58 }
59 }
60
61 @override
62 Widget build(BuildContext context) {
63 return NotificationListener<ScrollNotification>(
64 onNotification: (scrollNotification) {
65 if (scrollNotification is ScrollUpdateNotification) {
66 setState(() {
67 _showShadow = scrollNotification.metrics.pixels > 0;
68 });
69 }
70 return true;
71 },
72 child: Scaffold(
73 floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
74 floatingActionButton: widget.floating,
75 backgroundColor: widget.backgroundColor,
76 extendBody: true,
77 appBar: widget.title == null
78 ? null
79 : PreferredSize(
80 preferredSize: Size(
81 MediaQuery.of(context).size.width,
82 65.sp,
83 ),
84 child: CustomAppBar(
85 isLeadingVisible: widget.isLeadingVisible,
86 title: widget.title!,
87 actions: widget.actions,
88 ),
89 ),
90 body: SafeArea(
91 bottom: false,
92 child: Stack(
93 children: [
94 widget.body,
95 if (widget.isLoading)
96 Container(
97 color: Theme.of(context)
98 .scaffoldBackgroundColor
99 .withOpacity(0.9),
100 child: Center(
101 child: Lottie.asset(
103 height: 80.sp,
104 ),
105 ),
106 ),
107 ],
108 ),
109 ),
110 ),
111 );
112 }
113}
static const String loadingAnimation
Definition assets.dart:28
final VoidCallback onRefresh
final Widget floating
const CustomScaffold({ super.key, required this.body, this.isLoading=false, this.title, this.actions, this.bottomWidget, this.isLeadingVisible=true, this.backgroundColor, this.onRefresh, this.floating, })
override State< CustomScaffold > createState()
final List< Widget > actions
final PreferredSizeWidget bottomWidget
final bool isLeadingVisible
final Widget body
final Color backgroundColor
override void dispose()
final Widget child
override void initState()
bool _showShadow
class CustomScaffold extends StatefulWidget _scrollController
void _onScroll()
final Color backgroundColor
final Color color
Definition failures.dart:1
override Widget build(BuildContext context)
final String title