flutter 显示带有屏幕高度的导航抽屉-抖动

wfveoks0  于 2023-08-07  发布在  Flutter
关注(0)|答案(1)|浏览(156)

我是新来的Flutter,我正在使用导航抽屉在其中一个屏幕。在主屏幕中,我有标签栏,当我打开抽屉时,它会在标签栏内打开。我需要从标签栏里拿出来。我将附上下面的屏幕截图:
注意:我使用的是脚手架中的默认抽屉。


的数据

doinxwow

doinxwow1#

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}
  
  class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key}) : super(key: key);

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

class _MyHomePageState extends State<MyHomePage> {
  int _selectedIndex = 0;
  static const TextStyle optionStyle =
      TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
  static const List<Widget> _widgetOptions = <Widget>[
    Text(
      'Index 0: Home',
      style: optionStyle,
    ),
    Text(
      'Index 1: Business',
      style: optionStyle,
    ),
    Text(
      'Index 2: School',
      style: optionStyle,
    ),
  ];

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
       drawer: Drawer(
          child: Center(
            child: ElevatedButton(
              child: Text("Press"),
              onPressed: () {
                Navigator.push(
                    context, MaterialPageRoute(builder: (context) => Hello1()));
              },
            ),
          ),
        ),
       appBar: AppBar(
          title: const Text("data"),
         actions: [
           IconButton(
              icon: Badge(
                  label: Text('100'),
                  child: const Icon(
                    Icons.notifications_none_sharp,
                    color: Colors.black,
                  )),
              onPressed: () {
              },
            ),
         ]
        ),
     body: Center(
          child: _widgetOptions.elementAt(_selectedIndex),
        ),
      bottomNavigationBar: BottomNavigationBar(
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: Icon(Icons.home),
            label: 'Home',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.business),
            label: 'Business',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.school),
            label: 'School',
          ),
        ],
        currentIndex: _selectedIndex,
        selectedItemColor: Colors.amber[800],
        onTap: _onItemTapped,
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar:AppBar(
      title: Text('fdgdgdfgdfg')),
      body: Center(
          child: Text("data"),
        ),
    );
  }
}

字符串

相关问题