Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
custom_scaffold.dart
Go to the documentation of this file.
1import 'package:flutter/material.dart';
2import 'package:go_router/go_router.dart';
3
4import '../theme/color_palette.dart';
5import 'loading.dart';
6
7class CustomScaffold extends StatefulWidget {
9 super.key,
10 required this.body,
11 this.isLoading = false,
12 this.title,
13 this.actions,
14 this.bottomWidget,
15 this.isLeadingVisible = true,
16 this.backgroundColor,
17 this.onRefresh,
18 this.isBackButtonEnabled = true,
19 });
20
21 final Widget body;
22 final bool isLeadingVisible;
23 final bool isLoading;
24 final String? title;
25 final PreferredSizeWidget? bottomWidget;
26 final List<Widget>? actions;
27 final Color? backgroundColor;
28 final VoidCallback? onRefresh;
30
31 @override
32 State<CustomScaffold> createState() => _CustomScaffoldState();
33}
34
35class _CustomScaffoldState extends State<CustomScaffold> {
36 final ScrollController _scrollController = ScrollController();
37 bool _showShadow = false;
38
39 @override
40 void initState() {
41 super.initState();
42 _scrollController.addListener(_onScroll);
43 }
44
45 @override
46 void dispose() {
47 _scrollController.removeListener(_onScroll);
48 _scrollController.dispose();
49 super.dispose();
50 }
51
52 void _onScroll() {
53 if (_scrollController.offset > 0 && !_showShadow) {
54 setState(() => _showShadow = true);
55 } else if (_scrollController.offset <= 0 && _showShadow) {
56 setState(() => _showShadow = false);
57 }
58 }
59
60 @override
61 Widget build(BuildContext context) {
62 return NotificationListener<ScrollNotification>(
63 onNotification: (scrollNotification) {
64 if (scrollNotification is ScrollUpdateNotification) {
65 setState(() {
66 _showShadow = scrollNotification.metrics.pixels > 0;
67 });
68 }
69 return true;
70 },
71 child: Scaffold(
72 backgroundColor: widget.backgroundColor,
73 extendBody: true,
74 appBar: widget.title == null
75 ? null
76 : AppBar(
77 elevation: _showShadow ? 2 : 0,
78 surfaceTintColor: Colors.transparent,
79 shadowColor: Colors.black26,
80 bottom: widget.bottomWidget,
81 centerTitle: true,
82 title: Text(
83 widget.title!,
84 style: Theme.of(context)
85 .textTheme
86 .displaySmall
87 ?.copyWith(fontWeight: FontWeight.w900),
88 ),
89 actions: widget.actions,
90 automaticallyImplyLeading: false,
91 leading: widget.isLeadingVisible
92 ? OutlinedButton(
93 onPressed: (widget.isBackButtonEnabled && !widget.isLoading)
94 ? () {
95 context.pop();
96 }
97 : null,
98 child: const Icon(Icons.arrow_back),
99 )
100 : SizedBox.shrink(),
101 ),
102 body: widget.onRefresh != null ? RefreshIndicator(
104 backgroundColor: ColorPalette.white,
105 onRefresh: () async => widget.onRefresh?.call(),
106 child: buildBody(),
107 ) : buildBody(),
108 ),
109 );
110 }
111
112 Widget buildBody() {
113 return SafeArea(
114 bottom: false,
115 child: Stack(
116 children: [
117 widget.body,
118 if (widget.isLoading)
119 Positioned.fill(
120 child: AbsorbPointer(
121 child: Container(
122 color: Colors.black.withValues(alpha: 0.5),
123 child: const Loading(),
124 ),
125 ),
126 ),
127 ],
128 ),
129 );
130 }
131}
override void initState()
override void dispose()
class App extends StatefulWidget build(BuildContext context)
Definition app.dart:31
static const white
static const tiffanyBlue
final bool isBackButtonEnabled
final VoidCallback onRefresh
const CustomScaffold({ super.key, required this.body, this.isLoading=false, this.title, this.actions, this.bottomWidget, this.isLeadingVisible=true, this.backgroundColor, this.onRefresh, this.isBackButtonEnabled=true, })
override State< CustomScaffold > createState()
final List< Widget > actions
final PreferredSizeWidget bottomWidget
final bool isLeadingVisible
final Color backgroundColor
final Widget child
Widget buildBody()
bool _showShadow
class CustomScaffold extends StatefulWidget _scrollController
void _onScroll()
class Partner String
final Color color
Definition failures.dart:1
final VoidCallback onPressed
final String title
style Text( '${ 'scheduling.reference'.tr()}:${collection.internalCode}', style:Theme.of(context).textTheme.bodySmall,)
style SizedBox(height:2.h)