1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Feedback on Flutter BottomNavigationBar Implementation

Discussão em 'Mobile' iniciado por Stack, Outubro 6, 2024 às 00:23.

  1. Stack

    Stack Membro Participativo

    this is my bottomnavbar

    i want it look like this

    an i phone dock has a rounded corners

    I'm working on a Flutter app and just implemented a BottomNavigationBar with a custom AppBar. Below is the code for my HomePage widget:

    import 'package:flutter/material.dart';
    import 'dart:ui'; // For ImageFilter.blur

    import 'screens/profile.dart';
    import 'home_screen.dart';
    import 'book_appointment.dart';
    import 'screens/history.dart';

    class HomePage extends StatefulWidget {
    @override
    _HomePageState createState() => _HomePageState();
    }

    class _HomePageState extends State<HomePage> {
    int _bottomNavIndex = 0;

    final List<Widget> _pages = [
    HomeScreen(),
    AppointmentPage(),
    HistoryPage(),
    ];

    final List<IconData> _iconList = [
    Icons.home_filled,
    Icons.add_rounded,
    Icons.history,
    ];

    final List<String> _titleList = [
    'Home',
    'Appointments',
    'History',
    ];

    PreferredSizeWidget? _buildAppBar() {
    if (_bottomNavIndex == 0) {
    return PreferredSize(
    preferredSize: Size.fromHeight(60),
    child: AppBar(
    backgroundColor: Colors.transparent,
    flexibleSpace: Container(
    decoration: BoxDecoration(
    image: DecorationImage(
    image: AssetImage('assets/appbar.png'),
    fit: BoxFit.cover,
    ),
    ),
    ),
    title: GestureDetector(
    onTap: () {
    Navigator.push(
    context,
    MaterialPageRoute(builder: (context) => ProfilePage()),
    );
    },
    child: Row(
    children: [
    Padding(
    padding: EdgeInsets.only(top: 10),
    child: CircleAvatar(
    backgroundImage: AssetImage('assets/pogisivenz.png'),
    radius: 20,
    ),
    ),
    SizedBox(width: 10),
    Text(
    'Hi, Harold Pogi',
    style: TextStyle(color: Color(0xFFE5D9F2)),
    ),
    ],
    ),
    ),
    ),
    );
    }
    return null;
    }

    Widget _buildBottomNavigationBar() {
    return Container(
    decoration: BoxDecoration(
    color: Colors.white, // Background color for the dock
    borderRadius: BorderRadius.vertical(
    top: Radius.circular(30), // Rounded corners at the top
    ),
    boxShadow: [
    BoxShadow(color: Colors.black38, spreadRadius: 0, blurRadius: 10),
    ],
    ),
    margin: const EdgeInsets.only(bottom: 20.0), // Margin for the floating effect
    child: ClipRRect(
    borderRadius: BorderRadius.vertical(
    top: Radius.circular(30), // Match the top rounded corners
    ),
    child: BottomNavigationBar(
    items: <BottomNavigationBarItem>[
    BottomNavigationBarItem(
    icon: Icon(_iconList[0]),
    label: _titleList[0],
    ),
    BottomNavigationBarItem(
    icon: Icon(_iconList[1]),
    label: _titleList[1],
    ),
    BottomNavigationBarItem(
    icon: Icon(_iconList[2]),
    label: _titleList[2],
    ),
    ],
    currentIndex: _bottomNavIndex,
    selectedItemColor: const Color.fromARGB(255, 116, 23, 133),
    unselectedItemColor: Colors.black,
    onTap: (index) {
    setState(() {
    _bottomNavIndex = index;
    });
    },
    ),
    ),
    );
    }

    @override
    Widget build(BuildContext context) {
    return Scaffold(
    backgroundColor: Colors.transparent, // Make Scaffold background transparent
    appBar: _buildAppBar(),
    body: Stack(
    children: [
    Positioned.fill(
    child: Image.asset(
    'assets/splash.png',
    fit: BoxFit.cover,
    ),
    ),
    Positioned.fill(
    child: AnimatedSwitcher(
    duration: Duration(milliseconds: 300),
    child: _pages[_bottomNavIndex],
    ),
    ),
    ],
    ),
    bottomNavigationBar: _buildBottomNavigationBar(),
    );
    }
    }


    i tried changing it on my own many times but its not working pls help

    Continue reading...

Compartilhe esta Página