首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >底部溢出无限像素[暂停]

底部溢出无限像素[暂停]
EN

Stack Overflow用户
提问于 2019-06-10 06:16:56
回答 1查看 0关注 0票数 0

我试过底部导航栏。但是,我收到了一个意外的警告。

代码语言:javascript
运行
复制
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

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

/// This Widget is the main application widget.
class MyApp extends StatelessWidget {
  static const String _title = 'Flutter Code Sample';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: MyStatefulWidget(),
      theme: ThemeData(
        primaryColor: Colors.blueAccent,
        brightness: Brightness.light,
      ),
      debugShowCheckedModeBanner: false,
    );
  }
}

class MyStatefulWidget extends StatefulWidget {
  MyStatefulWidget({Key key}) : super(key: key);

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

class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  int _selectedIndex = 0;
final _widgetOptions = [
  ListGenerate(),
];

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

  @override
  Widget build(BuildContext context) {

    SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);

    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(
      systemNavigationBarColor: Colors.blue,
      statusBarColor: Colors.transparent,
    ));

    return Scaffold(
      body: Column(
        children: <Widget>[
          searchSection,
          _widgetOptions.elementAt(_selectedIndex),
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: Icon(Icons.info),
            title: Text('Info'),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.today),
            title: Text('Scheule'),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.location_on),
            title: Text('Location'),
          ),
        ],
        currentIndex: _selectedIndex,
        selectedItemColor: Colors.white,
        onTap: _onItemTapped,
        unselectedItemColor: Colors.white70,
        backgroundColor: Colors.blueAccent,
      ),
    );
  }
}

Widget searchSection = Container(
  padding: const EdgeInsets.all(32),
  child: Column(
    children: <Widget>[
      Container(
        padding: const EdgeInsets.only(top: 4, bottom: 4, right: 8, left: 8),
        decoration: BoxDecoration(
          border: Border.all(color: Colors.grey),
          borderRadius: BorderRadius.circular(12),
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Icon(Icons.dehaze, color: Colors.grey,),
            Text('Search', style:
            TextStyle(
              color: Colors.grey,
            ),
            ),
            Container(
              height: 42,
              width: 42,
              decoration: BoxDecoration(
                shape: BoxShape.circle,
                image: DecorationImage(
                    image: NetworkImage(
                        'https://www.w3schools.com/howto/img_avatar.png'
                    )
                ),
              ),
            ),
          ],
        ),
      )
    ],
  )
);

class ListGenerate extends StatefulWidget {
  @override
  _ListGenerateState createState() => _ListGenerateState();
}

class _ListGenerateState extends State<ListGenerate> {

  List<String> litems = ["1","2","Third","4"];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: <Widget>[
            ListView.builder
              (
                itemCount: litems.length,
                itemBuilder: (BuildContext context, int index)  {
                  return new Text(litems[index]);
                }
            ),
          ],
        ),
      ),
    );
  }
}
EN

回答 1

Stack Overflow用户

发布于 2019-06-10 15:42:24

代码语言:txt
复制
void main() => runApp(MyApp());

/// This Widget is the main application widget.
class MyApp extends StatelessWidget {
  static const String _title = 'Flutter Code Sample';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: MyStatefulWidget(),
      theme: ThemeData(
        primaryColor: Colors.blueAccent,
        brightness: Brightness.light,
      ),
      debugShowCheckedModeBanner: false,
    );
  }
}

class MyStatefulWidget extends StatefulWidget {
  MyStatefulWidget({Key key}) : super(key: key);

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

class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  int _selectedIndex = 0;
  final _widgetOptions = [
    ListGenerate(),
  ];

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

  @override
  Widget build(BuildContext context) {
    SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);

    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(
      systemNavigationBarColor: Colors.blue,
      statusBarColor: Colors.transparent,
    ));

    return Scaffold(
      body: Column(
        children: <Widget>[
          searchSection,
          Expanded(child: _widgetOptions.elementAt(_selectedIndex)),
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: Icon(Icons.info),
            title: Text('Info'),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.today),
            title: Text('Scheule'),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.location_on),
            title: Text('Location'),
          ),
        ],
        currentIndex: _selectedIndex,
        selectedItemColor: Colors.white,
        onTap: _onItemTapped,
        unselectedItemColor: Colors.white70,
        backgroundColor: Colors.blueAccent,
      ),
    );
  }
}

Widget searchSection = Container(
    padding: const EdgeInsets.all(32),
    child: Column(
      children: <Widget>[
        Container(
          padding: const EdgeInsets.only(top: 4, bottom: 4, right: 8, left: 8),
          decoration: BoxDecoration(
            border: Border.all(color: Colors.grey),
            borderRadius: BorderRadius.circular(12),
          ),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Icon(
                Icons.dehaze,
                color: Colors.grey,
              ),
              Text(
                'Search',
                style: TextStyle(
                  color: Colors.grey,
                ),
              ),
              Container(
                height: 42,
                width: 42,
                decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  image: DecorationImage(image: NetworkImage('https://www.w3schools.com/howto/img_avatar.png')),
                ),
              ),
            ],
          ),
        )
      ],
    ));

class ListGenerate extends StatefulWidget {
  @override
  _ListGenerateState createState() => _ListGenerateState();
}

class _ListGenerateState extends State<ListGenerate> {
  List<String> litems = ["1", "2", "Third", "4"];

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemCount: litems.length,
      scrollDirection: Axis.horizontal,
      itemBuilder: (BuildContext context, int index) {
        return Padding(
          padding: const EdgeInsets.all(8.0),
          child: new Text(litems[index]),
        );
      },
    );
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100006976

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档