Skip to content

Commit f6f26d0

Browse files
committed
💄 Migrate elevation and color to material rendering.
Related to #26 .
1 parent 5f99cf9 commit f6f26d0

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

lib/src/widget/fixed_appbar.dart

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import 'dart:ui' as ui;
66

77
import 'package:flutter/material.dart';
8+
import 'package:flutter/services.dart';
9+
import 'package:flutter_common_exports/flutter_common_exports.dart';
810

911
import '../constants/constants.dart';
1012

@@ -18,7 +20,7 @@ class FixedAppBar extends StatelessWidget {
1820
this.leading,
1921
this.centerTitle = true,
2022
this.backgroundColor,
21-
this.elevation = 2.0,
23+
this.elevation,
2224
this.actions,
2325
this.actionsPadding,
2426
this.height,
@@ -67,27 +69,18 @@ class FixedAppBar extends StatelessWidget {
6769

6870
@override
6971
Widget build(BuildContext context) {
72+
final Color color = (backgroundColor ?? Theme.of(context).primaryColor)
73+
.withOpacity(blurRadius > 0.0 ? 0.90 : 1.0);
74+
7075
Widget _title = title;
7176
if (centerTitle) {
7277
_title = Center(child: _title);
7378
}
79+
7480
Widget child = Container(
7581
width: Screens.width,
7682
height: (height ?? kToolbarHeight) + MediaQuery.of(context).padding.top,
7783
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
78-
decoration: BoxDecoration(
79-
boxShadow: elevation > 0
80-
? <BoxShadow>[
81-
BoxShadow(
82-
color: const Color(0x0d000000),
83-
blurRadius: elevation * 1.0,
84-
offset: Offset(0, elevation * 2.0),
85-
),
86-
]
87-
: null,
88-
color: (backgroundColor ?? Theme.of(context).primaryColor)
89-
.withOpacity(blurRadius > 0.0 ? 0.90 : 1.0),
90-
),
9184
child: Stack(
9285
children: <Widget>[
9386
if (automaticallyImplyLeading && Navigator.of(context).canPop())
@@ -132,6 +125,7 @@ class FixedAppBar extends StatelessWidget {
132125
],
133126
),
134127
);
128+
135129
if (blurRadius > 0.0) {
136130
child = ClipRect(
137131
child: BackdropFilter(
@@ -140,7 +134,21 @@ class FixedAppBar extends StatelessWidget {
140134
),
141135
);
142136
}
143-
return Material(type: MaterialType.transparency, child: child);
137+
138+
return AnnotatedRegion<SystemUiOverlayStyle>(
139+
value: context.themeData.appBarTheme.brightness.isDark
140+
? SystemUiOverlayStyle.light
141+
: SystemUiOverlayStyle.dark,
142+
child: Material(
143+
type: color.isTransparent
144+
? MaterialType.transparency
145+
: MaterialType.canvas,
146+
color: (backgroundColor ?? Theme.of(context).primaryColor)
147+
.withOpacity(blurRadius > 0.0 ? 0.90 : 1.0),
148+
elevation: elevation ?? context.themeData.appBarTheme.elevation ?? 4.0,
149+
child: child,
150+
),
151+
);
144152
}
145153
}
146154

0 commit comments

Comments
 (0)