cake_wallet/lib/src/widgets/nav_bar.dart

90 lines
2.1 KiB
Dart
Raw Normal View History

2020-01-04 19:31:52 +00:00
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class NavBar extends StatelessWidget implements ObstructingPreferredSizeWidget {
2020-01-08 12:26:34 +00:00
factory NavBar(
{BuildContext context,
Widget leading,
Widget middle,
Widget trailing,
Color backgroundColor}) {
return NavBar._internal(
leading: leading,
middle: middle,
trailing: trailing,
height: _height,
backgroundColor: backgroundColor);
2020-01-08 12:26:34 +00:00
}
2020-01-04 19:31:52 +00:00
factory NavBar.withShadow(
{BuildContext context,
Widget leading,
Widget middle,
Widget trailing,
Color backgroundColor}) {
return NavBar._internal(
leading: leading,
middle: middle,
trailing: trailing,
height: 80,
backgroundColor: backgroundColor,
2020-01-04 19:31:52 +00:00
decoration: BoxDecoration(
color: backgroundColor,
2020-01-04 19:31:52 +00:00
boxShadow: [
BoxShadow(
color: Color.fromRGBO(132, 141, 198, 0.11),
blurRadius: 8,
offset: Offset(0, 2))
]),
);
}
2020-01-08 12:26:34 +00:00
NavBar._internal(
{this.leading,
this.middle,
this.trailing,
this.backgroundColor,
this.decoration,
this.height = _height});
2020-01-04 19:31:52 +00:00
2020-01-08 12:26:34 +00:00
static const _originalHeight = 44.0; // iOS nav bar height
static const _height = 60.0;
2020-01-04 19:31:52 +00:00
final Widget leading;
final Widget middle;
final Widget trailing;
final Color backgroundColor;
final BoxDecoration decoration;
final double height;
@override
Widget build(BuildContext context) {
final pad = height - _originalHeight;
final paddingTop = pad / 2;
final _paddingBottom = (pad / 2);
return Container(
decoration: decoration ?? BoxDecoration(color: backgroundColor),
padding:
EdgeInsetsDirectional.only(bottom: _paddingBottom, top: paddingTop),
child: CupertinoNavigationBar(
leading: leading,
middle: middle,
trailing: trailing,
backgroundColor: backgroundColor,
border: null,
),
);
}
@override
Size get preferredSize => Size.fromHeight(height);
@override
bool shouldFullyObstruct(BuildContext context) {
return false;
}
}