Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.7 kB
4
Indexable
Never
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 Bottom Navigation Bar',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Bottom Navigation Bar'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _selectedIndex = 0;
  PageController rar = PageController(initialPage: 0);

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
    rar.animateToPage(_selectedIndex,
        duration: Duration(microseconds: 2), curve: Curves.bounceIn);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
          child: PageView(
        controller: rar,
        onPageChanged: (value) {
          setState(() {
            _selectedIndex = value;
          });
        },
        children: [
          Stack(
            alignment: AlignmentDirectional.bottomCenter,
            children: [
              Container(
                height: 300,
                padding: EdgeInsets.all(20),
                width: MediaQuery.of(context).size.width,
                decoration: BoxDecoration(
                    color: Colors.blue,
                    borderRadius: BorderRadius.only(
                        topLeft: Radius.circular(30),
                        topRight: Radius.circular(30))),
                child: Column(
                  children: [
                    Row(
                      children: [
                        Text(
                          'Random Text 1 Here',
                          style: TextStyle(letterSpacing: 2),
                        ),
                        Spacer(),
                        Text(
                          'Random Text 1 Here',
                          style: TextStyle(letterSpacing: 2),
                        )
                      ],
                    ),
                    Container(
                      margin: EdgeInsets.symmetric(vertical: 200),
                      child: Text(
                        'Random Text 1 Here',
                        style: TextStyle(letterSpacing: 2),
                      ),
                    ),
                  ],
                ),
              )
            ],
          ),
          Text('Email page', style: TextStyle(fontSize: 30, color: Colors.red)),
          Text('Profile page',
              style: TextStyle(
                  fontSize: 30, color: Color.fromARGB(255, 33, 37, 243))),
        ],
      )),
      bottomNavigationBar: BottomNavigationBar(
        backgroundColor: Color(0xFFFFEA03),
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: Icon(Icons.home),
            label: 'Home',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.email),
            label: 'Email',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.person),
            label: 'Profile',
          ),
        ],
        currentIndex: _selectedIndex,
        onTap: _onItemTapped,
        unselectedItemColor: Color.fromARGB(158, 33, 149, 243),
      ),
    );
  }
}