自定义AppBar

Posted by アライさん on 2019年10月22日

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
import 'package:flutter/material.dart';

///带返回按钮的简单appbar
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
final String title;
final Function callback;
final Color color;
final Color titleColor;
final Color backIconColor;

CustomAppBar(
{this.title,
this.callback,
this.color,
this.titleColor = Colors.white,
this.backIconColor = Colors.white});

@override
Widget build(BuildContext context) {
return AppBar(
elevation: 0.0,
title: Text(
title,
style: TextStyle(fontSize: 18.0, color: titleColor),
),
backgroundColor: color == null ? Theme.of(context).primaryColor : color,
leading: GestureDetector(
child: Icon(
Icons.arrow_back_ios,
size: 25.0,
color: backIconColor,
),
onTap: (callback == null)
? () {
Navigator.of(context).pop();
}
: callback,
),
);
}

@override
Size get preferredSize {
return Size.fromHeight(kToolbarHeight);
}
}