Flutter Sidebar und BottomNavigationBar?

Hallo!

Ich wollte gerade zu meiner App eine Sidebar und zusätzlich eine BottomNavigationBar hinzufügen. Jedoch funktioniert die Kombination von den Beiden nicht. Also die Sidebar ohne der BottomNavigationBar funktioniert und umgekerht. Das heißt auch die BottomNavigationBar funktioniert ohne Sidebar. ABer wenn ich beide zusammen einbinde dann geht es nicht.

Hier mein Code:

Sidebar:

import 'package:flutter/material.dart';

class Sidebar extends StatelessWidget {
  const Sidebar({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: SafeArea(child: Drawer(
        child: ListView(
          children: [
            DrawerHeader(
              decoration: BoxDecoration(
                color: Colors.red,
              ),
              child: Column(
                children: [Text('')],
              ),
            ),
            ListTile(
              title: Text("Vidoes"),
              onTap: () => Navigator.pushReplacementNamed(context, 'videos'),
            ),
            ListTile(
              title: Text("Filme"),
              onTap: () => Navigator.pushReplacementNamed(context, 'filme'),
            ),
            
          ],
        ),
      ),
      ),
    );
  }
}

BottomNavigationBar:

import 'package:flutter/material.dart';
import 'package:flutter_aposys/pages_export.dart';

class BottomNavigation extends StatefulWidget {
  const BottomNavigation({Key? key}) : super(key: key);

  @override
  State<BottomNavigation> createState() => _BottomNavigationState();
}

class _BottomNavigationState extends State<BottomNavigation> {
  int currentIndex = 0;
  final screens = [
    Home(),
    Maps(),
    Kalender(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: screens[currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        backgroundColor: Colors.grey,
        selectedItemColor: Colors.red,
        currentIndex: currentIndex,
        onTap: (index)=> setState(() {
          currentIndex=index;
        }),
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'),
          BottomNavigationBarItem(icon: Icon(Icons.map), label: 'Maps'),
          BottomNavigationBarItem(icon: Icon(Icons.calendar_month), label: 'Kalender'),
        ],
      ),
    );
  }
}

Bite um eure Hilfe!

Der Code für die main Datei und für die Home Datei ist in der Antwort zu finden!

...zum Beitrag

Main:

import 'package:flutter/material.dart';


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

class Media extends StatelessWidget {
  const Media({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.red,
      ),
      home: Home(),
      routes: {
        'home': (context) => Home(),
        'videos': (context) => Videos(),
        'filme': (context) => Filme(),
      
      },
    );
  }
}



Home:

import 'package:flutter/material.dart';

import '../sidebar/sidebar.dart';

class Home extends StatelessWidget {
  const Home({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Home"),

      ),
      drawer: Sidebar(),
      bottomNavigationBar: BottomNavigation(),
      body: Container(
      
            ),
      
          );
        }
      }
      
...zur Antwort