•  


Work with tabs | Flutter

Work with tabs

Working with tabs is a common pattern in apps that follow the Material Design guidelines. Flutter includes a convenient way to create tab layouts as part of the material library .

This recipe creates a tabbed example using the following steps;

  1. Create a TabController .
  2. Create the tabs.
  3. Create content for each tab.

1. Create a TabController

#

For tabs to work, you need to keep the selected tab and content sections in sync. This is the job of the TabController .

Either create a TabController manually, or automatically by using a DefaultTabController widget.

Using DefaultTabController is the simplest option, since it creates a TabController and makes it available to all descendant widgets.

dart
return
 MaterialApp
(

  home: 
DefaultTabController
(

    length: 
3
,

    child: 
Scaffold
(),

  ),

);

2. Create the tabs

#

When a tab is selected, it needs to display content. You can create tabs using the TabBar widget. In this example, create a TabBar with three Tab widgets and place it within an AppBar .

dart
return
 MaterialApp
(

  home: 
DefaultTabController
(

    length: 
3
,

    child: 
Scaffold
(

      appBar: 
AppBar
(

        bottom: 
const
 TabBar
(

          tabs: [

            Tab
(icon: 
Icon
(
Icons
.directions_car)),

            Tab
(icon: 
Icon
(
Icons
.directions_transit)),

            Tab
(icon: 
Icon
(
Icons
.directions_bike)),

          ],

        ),

      ),

    ),

  ),

);

By default, the TabBar looks up the widget tree for the nearest DefaultTabController . If you're manually creating a TabController , pass it to the TabBar .

3. Create content for each tab

#

Now that you have tabs, display content when a tab is selected. For this purpose, use the TabBarView widget.

dart
body: 
const
 TabBarView
(

  children: [

    Icon
(
Icons
.directions_car),

    Icon
(
Icons
.directions_transit),

    Icon
(
Icons
.directions_bike),

  ],

),

Interactive example

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: DefaultTabController(
        length: 3,
        child: Scaffold(
          appBar: AppBar(
            bottom: const TabBar(
              tabs: [
                Tab(icon: Icon(Icons.directions_car)),
                Tab(icon: Icon(Icons.directions_transit)),
                Tab(icon: Icon(Icons.directions_bike)),
              ],
            ),
            title: const Text('Tabs Demo'),
          ),
          body: const TabBarView(
            children: [
              Icon(Icons.directions_car),
              Icon(Icons.directions_transit),
              Icon(Icons.directions_bike),
            ],
          ),
        ),
      ),
    );
  }
}
- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본