- flutter

공통 AppBar 만들기

나둥식 2022. 11. 21. 12:11

 

1️⃣ 메서드로 파일을 따로 생성한다.

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

AppBar BuildAppBar() {
  return AppBar(
    title: Row(
      children: [
        Text("좌동"),
        SizedBox(width: 4.0),
        Icon(
          CupertinoIcons.chevron_down,
          size: 15,
        ),
      ],
    ),
    actions: [
      IconButton(onPressed: () {}, icon: Icon(CupertinoIcons.search)),
      IconButton(onPressed: () {}, icon: Icon(CupertinoIcons.list_dash)),
      IconButton(onPressed: () {}, icon: Icon(CupertinoIcons.bell)),
    ],
    bottom: PreferredSize(
      preferredSize: Size.fromHeight(0.5),
      child: Divider(
        thickness: 0.5,
        height: 0.5,
        color: Colors.grey,
      ),
    ),
  );
}

 

 

2️⃣ 페이지에 적용

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: BuildAppBar(),
    );
  }