首页 > 解决方案 > Flutter CupertinoPicker 不渲染

问题描述

试图让 Flutter CupertinoPicker 在 Flutter 1.7 上工作。没有花哨的东西,只是脚手架体内的基本代码......

只使用强制元素......甚至尝试了其他人的示例代码,没有任何效果。

CupertinoPicker(
     itemExtent: 30.0,
     onSelectedItemChanged: (int idx) {
       setState(() {
          _prayer.rebuild((b) =>
             b..category = listOfStrings[idx]);
          });
       },
     children: List<Widget>.generate(
     listOfStrings.length,
     (int i) {
        return Text('Dummy Text');
     },
   ),
 )
flutter: Another exception was thrown: RenderFlex children have non-zero flex but incoming height constraints are unbounded.
flutter: Another exception was thrown: RenderBox was not laid out: RenderFlex#fdf27 relayoutBoundary=up3 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
flutter: Another exception was thrown: RenderBox was not laid out: RenderFlex#052f5 relayoutBoundary=up2 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
flutter: Another exception was thrown: RenderBox was not laid out: RenderPadding#0d6c9 relayoutBoundary=up1 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
flutter: Another exception was thrown: RenderFlex children have non-zero flex but incoming height constraints are unbounded.
flutter: Another exception was thrown: RenderBox was not laid out: RenderFlex#fdf27 relayoutBoundary=up3 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderFlex#052f5 relayoutBoundary=up2 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderPadding#0d6c9 relayoutBoundary=up1 NEEDS-PAINT
flutter: Another exception was thrown: NoSuchMethodError: The method '>' was called on null.

Android Picker 工作......是否需要父 Widget 应该基于 Cupertino 或其他东西?

标签: flutterflutter-layout

解决方案


Expanded(      
    child:  
      
      CupertinoPicker(
        backgroundColor: Colors.white,
        onSelectedItemChanged: (index) {
        },
        itemExtent: 50.0,
        children:new List<Widget>.generate(
                        companyList.length, (int index) {
                      return new Center(
                        child: new Text(
                          "${companyList[index]}",
                          style: TextStyle(fontSize: 16,fontFamily: 
                           'HelveticaRegular'),),
                      );})
     ))

推荐阅读