본문 바로가기
Dart&Flutter

[ Flutter ] 플러터 appbar 색상 변경하기 / primarySwatch 속성

by 알기 쉬운 코딩 사전 2023. 8. 31.
반응형

 

appbar 부분 배경색이 존재하지 않는다.

 

플러터 appbar에 색상을 추가해주려면,

them 속성에서 primarySwatch를 본인이 원하는 색으로 추가해 준다.

primarySwatch: Colors.blue

 

수정 전 main.dart 코드

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const RegisterPage(),
    );
  }
}

class RegisterPage extends StatefulWidget {
  const RegisterPage({super.key});

  @override
  State<RegisterPage> createState() => _RegisterPageState();
}

class _RegisterPageState extends State<RegisterPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('회원가입 페이지'),
      ),
    );
  }
}

 

불필요한 속성은 삭제해 주고 primarySwatch를 추가해 주었다.

 

수정 후 main.dart 코드

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        //primarySwatch 추가
        primarySwatch: Colors.blue,
      ),
      home: const RegisterPage(),
      //debug 표시 삭제 속성
      debugShowCheckedModeBanner: false,
    );
  }
}

class RegisterPage extends StatefulWidget {
  const RegisterPage({super.key});

  @override
  State<RegisterPage> createState() => _RegisterPageState();
}

class _RegisterPageState extends State<RegisterPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('회원가입 페이지'),
      ),
    );
  }
}

 

수정 후 플러터 화면

반응형

댓글