App/Flutter

[ FLUTTER 커스텀 ] AppBar

거북 2021. 12. 13. 11:18

 

* app_bar.dart

enum AppBarLeft { none, back }
enum AppBarRight { none, notify }

PreferredSizeWidget buildAppBar(BuildContext context,
    {AppBarLeft left = AppBarLeft.none,
    AppBarRight right = AppBarRight.none,
    String title = '',
    double height = 56}) {
  return AppBar(
    automaticallyImplyLeading: left == AppBarLeft.none ? false : true,
    title: title.isEmpty ? null : Text(title),
    toolbarHeight: height,
    actions: right == AppBarRight.notify
        ? [NotifyButton()]
        : null,
  );
}

class NotifyButton extends StatefulWidget {
  const NotifyButton({Key? key}) : super(key: key);

  @override
  _NotifyButtonState createState() => _NotifyButtonState();
}

class _NotifyButtonState extends State<NotifyButton> {
  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: InnerConfig.normal - 12),
      child: InkWell(
          borderRadius: RadiusConfig.normal,
          onTap: () {},
          child: Container(
              padding: const EdgeInsets.symmetric(horizontal: 12),
              child: SvgPicture.asset('assets/icons/bell.svg'))),
    );
  }
}

 

* Use

return Scaffold(
	appBar: buildAppBar(
    	title: 'Title',
    ),
);