3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Flutter】bottomNavigationBar をカスタマイズしたくないか??俺はしたいぞ。

Last updated at Posted at 2020-03-24

2020/03/24 : 更新
2020/03/27 : 【更新】styleを調整した

学び始めたばかりなので、、よくない点があれば教えてください!!!!

UX的にも
もっとみんなにbottomNavigationBarを使ってほしいから書いた。

随時説明も追記していきたいと思ってる!

こんな感じになるよ

Screen Shot 2020-03-27 at 21.49.27.png


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

import 'package:flutter-app/view/components/AppFirebaseAuthProvider.dart';

import 'package:flutter-app/view/screen/Information.dart';
import 'package:flutter-app/view/screen/Map.dart';
import 'package:flutter-app/view/screen/Account.dart';

class _HomeState extends State<Home> with SingleTickerProviderStateMixin {

  @override
  Widget build(BuildContext context) {
    final auth = Provider.of<AppLineAuthProvider>(context);
    return DefaultTabController(
      length: 3,
      child: Scaffold(
        backgroundColor: Colors.white,
          bottomNavigationBar: SafeArea(
            child: ColoredTabBar(
              color: Colors.white,
              tabBar: TabBar(
                labelColor: Colors.white,
                indicatorSize: TabBarIndicatorSize.label,
                unselectedLabelColor: Colors.indigo,
                indicator: BoxDecoration(
                  borderRadius: BorderRadius.circular(50),
                  color: Colors.indigo,
                ),
                tabs: <Widget>[
                  Tab(
                    child: Container(
                      child: Center(
                        child: Row(
                            children: <Widget>[
                              Spacer(),
                              Icon(
                                Icons.place,
                              ),
                              Text("マップ"),
                              Spacer()
                            ]
                        ),
                      ),
                    ),
                  ),
                  Tab(
                    child: Container(
                      child: Align(
                        child: Row(
                            children:<Widget>[
                              Spacer(),
                              Icon(Icons.notifications),
                              Text("お知らせ"),
                              Spacer()
                          ]
                        ),
                      ),
                    ),
                  ),
                  Tab(
                    child: Container(
                      child: Center(
                        child: Row(
                          children: <Widget>[
                            Spacer(),
                            Icon(Icons.person),
                            Text("マイページ"),
                            Spacer()
                          ],
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
          body: TabBarView(
//            physics: NeverScrollableScrollPhysics(),
            children: <Widget>[
              new UmbrellaMap(),
              new UmbrellaInformation(),
              new AppSetting(),
            ]
          )),
    );
  }
}

class ColoredTabBar extends StatelessWidget implements PreferredSizeWidget {
  final PreferredSizeWidget tabBar;
  final Color color;

  ColoredTabBar({@required this.tabBar, @required this.color});

  @override
  Widget build(BuildContext context) {
    return Ink(
      color: color,
      child: tabBar,
    );
  }

  @override
  Size get preferredSize => tabBar.preferredSize;
}

参考にしました!
ありがとうございます!
https://qiita.com/mkosuke/items/3e33d71ef4de74364f87#comment-9525df20df727d3d5dae

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?