如何增加图标大小而不会出现溢出错误?

问题描述 投票:0回答:2

我需要在应用栏中显示2个图标,在左侧显示一个图标,在右侧显示一个图标。

我的代码

Scaffold(
  appBar: AppBar(
    leading: FlatButton.icon(
        onPressed: () {},
        icon: Icon(Icons.info,size: 20,color: Colors.white,),
  ...

我可以这样做,但是图标的尺寸太小,如下图所示

enter image description here

如果我将图标大小增加20倍以上,则会出现overflow错误。

我也尝试用FlatButton小部件包装Wrap小部件,但仍然得到相同的结果。

如何增加图标的大小?

flutter flutter-layout
2个回答
0
投票

使用PreferredSize:

  appBar: PreferredSize(
    preferredSize: Size.fromHeight(50.0),
    child: Container(
      child: AppBar(
        leading: Icon(
          Icons.info,
          size: 50,
          color: Colors.white,
        ),
      ),
    ),
  ),

0
投票

我无法重现您收到的错误。

import 'package:flutter/material.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Plugin example app'),
          centerTitle: true,
          leading: IconButton(
            icon: Icon(Icons.info),
            iconSize: 40.0,
            onPressed: () {},
          ),
          actions: <Widget>[
            IconButton(
              icon: Icon(Icons.notifications),
              iconSize: 40.0,
              onPressed: () {},
            )
          ],
        ),
      ),
    );
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.