Flutter-如何解决iOS和Android之间的这种差异?

时间:2019-02-17 17:05:38

标签: android ios flutter

我正在学习Flutter,所以我正在做一些测试。在上一个测试应用程序中,我实现了带有图标的ExpansionPanel。图标显示在iOS上,但不显示在Android上。知道为什么以及如何解决这个问题吗?

    new Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
            Column(
                children: <Widget>[
                    Icon(Icons.time_to_leave, size: _iconSize, color: _iconColor),
                    Padding(padding: EdgeInsets.only(top: _textPadding)),
                    Text("Car", style: new TextStyle(fontSize: _fontSize))
                ],
            ),

        ],
    ),

first屏幕截图来自iOS模拟器(预期结果),second屏幕截图来自Android模拟器(错误的)。构建应用程序时,结果是相同的。

根据要求编辑完整代码(我删除了不会改变问题的无用部分:

import 'package:flutter/material.dart';


class Criterias extends StatefulWidget {
  CriteriaState createState() => new CriteriaState();
}

class NewItem {
  bool isExpanded;
  final String header;
  final Widget body;
  final Icon iconpic;
  NewItem(this.isExpanded, this.header, this.body, this.iconpic);
}

double discretevalue = 2.0;
double hospitaldiscretevalue = 25.0;

class CriteriaState extends State<Criterias> {

  bool firstStart = true;
  List<NewItem> items;
  final double _textPadding = 4;
  final double _fontSize = 20;
  final double _panelPadding = 15.0;
  int _bottomNavigationBarIndex = 0;
  static bool _defaultExpanded = true;
  bool _expandOrCollapse = _defaultExpanded;
  Color _iconColor = Colors.lightBlue;

  void _expandCollapse () {
    setState(() {
      _expandOrCollapse = !_expandOrCollapse;
      for (var item in items) {
        item.isExpanded = _expandOrCollapse;
      }
    });
  }

  void onTabTaped(int index) {
    setState(() {
      print(index);
      _bottomNavigationBarIndex = index;
    });
  }

  ListView List_Criteria;
  Widget build(BuildContext context) {
    if (firstStart) {
      firstStart = false;
      double _iconSize = MediaQuery.of(context).size.width / 6;
      items = <NewItem>[
        new NewItem(
            _defaultExpanded,
            'Travel',
            new Padding(
                padding: new EdgeInsets.all(_panelPadding),
                child: Column(
                  children: <Widget>[
                    new Row(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: <Widget>[
                        Column(
                          children: <Widget>[
                            Icon(Icons.time_to_leave, size: _iconSize, color: _iconColor),
                            Padding(padding: EdgeInsets.only(top: _textPadding)),
                            Text("Car", style: new TextStyle(fontSize: _fontSize))
                          ],
                        ),
                      ]
                    ),

                    new Padding(padding: EdgeInsets.only(top: 20)),

                    new Row(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: <Widget>[
                        Column(
                          children: <Widget>[
                            Icon(Icons.timeline, size: _iconSize, color: _iconColor),
                            Padding(padding: EdgeInsets.only(top: _textPadding)),
                            Text("Path", style: new TextStyle(fontSize: _fontSize))
                          ],
                        ),
                      ]
                    ),
                  ],
                )
                  ),
            new Icon(Icons.time_to_leave),
        ),
      ];
    }

    List_Criteria = new ListView(
      children: [
        Padding(
          padding: EdgeInsets.symmetric(vertical: 10),
          child: 
            Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: <Widget>[
                InkWell(
                  onTap: () => _expandCollapse(),
                  child: Text(_expandOrCollapse ? "Collapse All" : "Expand All", style: new TextStyle(color: Colors.lightBlue, fontSize: 15)),
                ),
                SizedBox(width: 10),
              ],
            ),
        ),

        new Padding(
          padding: new EdgeInsets.all(0.0),
          child: new ExpansionPanelList(
            expansionCallback: (int index, bool isExpanded) {
              setState(() {
                items[index].isExpanded = !items[index].isExpanded;
              });
            },
            children: items.map((NewItem item) {
              return new ExpansionPanel(
                headerBuilder: (BuildContext context, bool isExpanded) {
                  return new ListTile(
                      leading: item.iconpic,
                      title: new Text(
                        item.header,
                        textAlign: TextAlign.left,
                        style: new TextStyle(
                          fontSize: 20.0,
                          fontWeight: FontWeight.w400,
                        ),
                      ));
                },
                isExpanded: item.isExpanded,
                body: item.body,
              );
            }).toList(),
          ),
        )
      ],
    );

    Scaffold scaffold = new Scaffold(
      appBar: new AppBar(
        title: new Text("Application"),
      ),
      body: _bottomNavigationBarIndex == 0 ? List_Criteria : Container(
        child:
          Column(
            children: <Widget>[
              Padding(
                padding: EdgeInsets.only(top: 8, left: 8),
                child: 
                  Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: <Widget>[
                      //CloseButton()
                      Icon(Icons.close, size: 30)
                    ],
                  ),
              ),

              Divider(
                color: Colors.black,
              ),

              Container(),
            ],
          )
      ),
      bottomNavigationBar: 
      BottomNavigationBar(
        onTap: onTabTaped,
        currentIndex: _bottomNavigationBarIndex,
        type: BottomNavigationBarType.fixed,
        items:<BottomNavigationBarItem>[
      BottomNavigationBarItem(icon: Icon(Icons.attach_money), title: Text("Payment")),
      BottomNavigationBarItem(icon: Icon(Icons.attach_money), title: Text("Payment")),
    ]
      ),
    );
    return scaffold;
  }
}


void main() {
  runApp(
    MaterialApp(home:Criterias()));
}

1 个答案:

答案 0 :(得分:0)

好吧,在Flutter Bug Tracker中进行挖掘之后,当使用大字符/图标时,Flutter中似乎有一个Bug。图标随机显示在某些设备上,而不显示在其他设备上。