개발/플루터(flutter)

flutter bottom tab

----___<<<<< 2020. 4. 23. 16:37

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: Test(),
    );
  }
  
}

class Test extends StatefulWidget {
  @override
  _TestState createState() => _TestState();
}

class _TestState extends State<Test> {

  int _selectedIndex = 0;
  List<Widget> _widgetOptions = <Widget>[
    aaaaa(),
    Text(
      'Index 1: Business',
    ),
    Text(
      'Index 2: School',
    ),
  ];

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("appbar"),
      ),
      body: Center(
        child: _widgetOptions.elementAt(_selectedIndex),
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: Icon(Icons.home),
            title: Text('Home'),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.business),
            title: Text('Business'),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.school),
            title: Text('School'),
          ),
        ],
        currentIndex: _selectedIndex,
        onTap: _onItemTapped,
      ),

    );
  }
}


class aaaaa extends StatefulWidget {
  @override
  _aaaaaState createState() => _aaaaaState();
}

class _aaaaaState extends State<aaaaa> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Text("여기입니당"),
      )
    );
  }
}



 

참조

[1] - https://api.flutter.dev/flutter/material/BottomNavigationBar-class.html

 

'개발 > 플루터(flutter)' 카테고리의 다른 글

Future  (0) 2020.05.03
flutter icons  (0) 2020.04.23
flutter adb exited with exit code 1  (0) 2020.04.21
bottom tabBar  (0) 2020.04.12
커플게임 앱 - 3  (0) 2020.04.09