반응형
Tabbar 위젯 기본 코드
import 'package:flutter/material.dart';
/// Flutter code sample for [TabBar].
void main() => runApp(const TabBarApp());
class TabBarApp extends StatelessWidget {
const TabBarApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: const TabBarExample(),
);
}
}
class TabBarExample extends StatelessWidget {
const TabBarExample({super.key});
@override
Widget build(BuildContext context) {
return DefaultTabController(
initialIndex: 1,
length: 3,
child: Scaffold(
appBar: AppBar(
title: const Text('TabBar Sample'),
bottom: const TabBar(
tabs: <Widget>[
Tab(
icon: Icon(Icons.cloud_outlined),
),
Tab(
icon: Icon(Icons.beach_access_sharp),
),
Tab(
icon: Icon(Icons.brightness_5_sharp),
),
],
),
),
body: const TabBarView(
children: <Widget>[
Center(
child: Text("It's cloudy here"),
),
Center(
child: Text("It's rainy here"),
),
Center(
child: Text("It's sunny here"),
),
],
),
),
);
}
}
탭 String으로 변경
TabBar(
tabs: <Widget>[
Tab(child: Text("바나나",style: TextStyle(fontWeight: FontWeight.w800))),
Tab(child: Text("사과",style: TextStyle(fontWeight: FontWeight.w800))),
Tab(child: Text("딸기",style: TextStyle(fontWeight: FontWeight.w800))),
],
),
Indicator 탭 꽉 차게 설정
TabBar(
// indicator 색 설정
indicator: BoxDecoration(color: Colors.green[100]),
// 꽉차게 설정
indicatorSize: TabBarIndicatorSize.tab,
tabs: <Widget>[
const Tab(
child: Text("바나나",style: TextStyle(fontWeight: FontWeight.w800))
),
const Tab(
child: Text("사과",style: TextStyle(fontWeight: FontWeight.w800))
),
const Tab(
child: Text("딸기",style: TextStyle(fontWeight: FontWeight.w800))
),
],
),
탭 레이블 컬러 설정
TabBar(
indicator: BoxDecoration(color: Colors.green[100]),
indicatorSize: TabBarIndicatorSize.tab,
// 선택된 탭 label 컬러
labelColor: Colors.white,
// 선택되지않은 탭 label 컬러
unselectedLabelColor: Colors.black ,
... )
참고자료
https://api.flutter.dev/flutter/material/TabBar-class.html
반응형
'Flutter' 카테고리의 다른 글
[Flutter/Dart] dart 문법 열거형 enum의 효율적인 사용 방법 (0) | 2024.04.05 |
---|---|
[Flutter] Parse Issue (Xcode): Module 'sqflite' not found 에러 해결 (0) | 2024.03.20 |
[Flutter] Sidebar, Side Navigation 구현하기 (sidebarx) (1) | 2024.02.05 |
[Flutter] 플러터로 달력 구현하기 (flutter_calendar_carousel) (0) | 2024.01.02 |
MVVM 패턴이란? MVC 패턴과의 차이? (1) | 2023.12.31 |