SliverGeometry无效:Flutter中的“ maxPaintExtent”小于“ paintExtent”

时间:2019-07-10 06:14:55

标签: flutter

我的整个应用程序可以在Emulator和Moto-G5S中完美运行,但是我发现在Samsung Galaxy A6 +的SliverGrid View中加载数据时出错。 我的错误是“ maxPaintExtent小于paintExtent,maxPaintExtent是177.5,但是paintExtent是612.0。根据定义,条子不能绘制超过其可以绘制的最大值!”

我尝试了不同的SliverGrid gridDelegate,例如maxCrossAxisExtent:300.0,mainAxisSpacing:5.0,crossAxisSpacing:5.0,childAspectRatio:1.0,但仍然无法解决。 我如何设置maxPaintExtent? 预先感谢。

series.dart

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

  @override
  _SeriesScreenState createState() => new _SeriesScreenState();
}

class _SeriesScreenState extends State<SeriesScreen> {
  bool isHomeDataLoading;

  @override
  void initState() {
    super.initState();
    isHomeDataLoading = false;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: ComComp.getAppBar(COLORS.SERIES_THEME_COLOR, STRING_NAME.SERIES_MOVIE),
      body: CustomScrollView(
        shrinkWrap: false,
        slivers: <Widget>[
          makeHeader(STRING_NAME.MOVIE),
          Container(
            child: FutureBuilder(
                future: Services.getMovies(),
                initialData: [],
                builder: (context, snapshot) {
                  //if (snapshot.connectionState == ConnectionState.done) {
                    return ComComp.sliverGridMovies(snapshot, movieGridClicked);
                  //} else {
                  //  ComComp.circularProgress(COLORS.SERIES_THEME_COLOR);
                 // }
                }),
          ),

          makeHeader(STRING_NAME.SERIES),
          Container(
            child: FutureBuilder(
                future: Services.getSeries(),
                initialData: [],
                builder: (context, snapshot) {
                  //if (snapshot.connectionState == ConnectionState.done) {
                    return ComComp.sliverGridSeries(snapshot, seriesGridClicked);
                  //} else {
                  //  ComComp.circularProgress(COLORS.SERIES_THEME_COLOR);
                  //}
                }),
          ),
        ],
      ),
    );
  }

  setLoading(bool loading) {
    setState(() {
      isHomeDataLoading = loading;
    });
  }

  fetch() {setLoading(true);}
}

SliverPersistentHeader makeHeader(String headerText) {
  return SliverPersistentHeader(
    pinned: true,
    delegate: _SliverAppBarDelegate(
      minHeight: 60.0,
      maxHeight: 130.0,
      child: Container(
        //color: COLORS.COMPLY,
          color: COLORS.CRAFT_THEME_COLOR,
          child: Center(
            child: Text(headerText,
              style: TextStyle(
                  fontFamily: 'Chewy', fontWeight: FontWeight.w500,
                  color: Colors.white, fontSize: 32, letterSpacing: 2.0),
            ),
          )
      ),
    ),
  );
}



class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
  _SliverAppBarDelegate({
    @required this.minHeight,
    @required this.maxHeight,
    @required this.child,
  });

  final double minHeight;
  final double maxHeight;
  final Widget child;
  @override
  double get minExtent => minHeight;
  @override
  double get maxExtent => math.max(maxHeight, minHeight);
  @override
  Widget build(
      BuildContext context,
      double shrinkOffset,
      bool overlapsContent)
  {
    return SizedBox.expand(child: child);
  }
  @override
  bool shouldRebuild(_SliverAppBarDelegate oldDelegate) {
    return maxHeight != oldDelegate.maxHeight;
  }
}

movieGridClicked(BuildContext context, CellModel model) {
  // Grid Click
      Navigator.push(context,
          MaterialPageRoute(
              builder: (context) => VideoPlayerScreen(model.title, model.url)));
  //SnackBar Msg:
  //Scaffold.of(context).showSnackBar(new SnackBar(content: Text(model.title),));
}

seriesGridClicked(BuildContext context, SeriesModel model) {
  // Grid Click
      Navigator.push(context,
          MaterialPageRoute(
              builder: (context) => EpisodeScreen(model.id.toString(), model.title)));
  //SnackBar Msg:
  //Scaffold.of(context).showSnackBar(new SnackBar(content: Text(model.title),));
}

comcomp.dart

static SliverGrid sliverGridMovies (AsyncSnapshot snapshot, Function gridClicked){
    var values = snapshot.data;

    return SliverGrid(
      delegate: SliverChildBuilderDelegate(
            (BuildContext context, int index) {
          return GestureDetector(
            child: Cell(COLORS.SERIES_THEME_COLOR, values[index]),
            onTap: () => gridClicked(context, values[index]),
          );
        },
        childCount: values == null ? 0 : values.length,
      ),
      gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
        maxCrossAxisExtent: 300.0,
        mainAxisSpacing: 5.0,
        crossAxisSpacing: 5.0,
        childAspectRatio: 1.0,
      ),
    );
  }

错误:

I/flutter (21918): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═══
I/flutter (21918): The following assertion was thrown during performLayout():
I/flutter (21918): SliverGeometry is not valid: The "maxPaintExtent" is less than the "paintExtent".
I/flutter (21918): The maxPaintExtent is 177.5, but the paintExtent is 612.0. By definition, a sliver can't paint more
I/flutter (21918): than the maximum that it can paint!
I/flutter (21918): The RenderSliver that returned the offending geometry was:
I/flutter (21918):   RenderSliverGrid#7ddfe relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (21918):   creator: SliverGrid ← FutureBuilder<List<dynamic>> ← Container ← Viewport ←
I/flutter (21918):   IgnorePointer-[GlobalKey#8bde6] ← Semantics ← Listener ← _GestureSemantics ←
I/flutter (21918):   RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#55565] ← Listener ← _ScrollableScope
I/flutter (21918):   ← _ScrollSemantics-[GlobalKey#062a8] ← ⋯
I/flutter (21918):   parentData: paintOffset=Offset(0.0, 0.0) (can use size)
I/flutter (21918):   constraints: SliverConstraints(AxisDirection.down, GrowthDirection.forward,
I/flutter (21918):   ScrollDirection.forward, scrollOffset: 379.7, remainingPaintExtent: 612.0, overlap: 60.0,
I/flutter (21918):   crossAxisExtent: 360.0, crossAxisDirection: AxisDirection.right, viewportMainAxisExtent: 612.0,
I/flutter (21918):   remainingCacheExtent: 1112.0 cacheOrigin: -250.0 )
I/flutter (21918):   geometry: SliverGeometry(scrollExtent: 177.5, paintExtent: 612.0, maxPaintExtent: 177.5,
I/flutter (21918):   hasVisualOverflow: true, cacheExtent: 1112.0)
I/flutter (21918):   currently live children: 0 to 1

I/flutter (21918)════════════════════════════════════════════════════
I/flutter (21918): Another exception was thrown: SliverGeometry is not valid: The "maxPaintExtent" is less than the "paintExtent".
I/chatty  (21918): uid=10250(com.globaltoons.globaltoons_mobile) 1.ui identical 1 line
I/flutter (21918): Another exception was thrown: SliverGeometry is not valid: The "maxPaintExtent" is less than the "paintExtent".
D/ViewRootImpl@93b5099[MainActivity](21918): ViewPostIme pointer 0
D/ViewRootImpl@93b5099[MainActivity](21918): ViewPostIme pointer 1
D/ViewRootImpl@93b5099[MainActivity](21918): ViewPostIme pointer 0

1 个答案:

答案 0 :(得分:0)

我有同样的问题。

我更新了flutter和dart版本,重新启动了ide。

然后在“工具”标签下,依次单击“ flutter”,“ flutter clean”和“ flutter upgrade”

这出于某种原因解决了问题