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

D'P*_*tel 5 flutter

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

\n\n

我尝试了不同的 SliverGrid gridDelegate,例如 maxCrossAxisExtent: 300.0、mainAxisSpacing: 5.0、crossAxisSpacing: 5.0、childAspectRatio: 1.0 但我仍然无法修复它。\n我如何设置 maxPaintExtent?\n提前谢谢。

\n\n

系列.dart

\n\n
class SeriesScreen extends StatefulWidget {\n  SeriesScreen({Key key}) : super(key: key);\n\n  @override\n  _SeriesScreenState createState() => new _SeriesScreenState();\n}\n\nclass _SeriesScreenState extends State<SeriesScreen> {\n  bool isHomeDataLoading;\n\n  @override\n  void initState() {\n    super.initState();\n    isHomeDataLoading = false;\n  }\n\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      backgroundColor: Colors.white,\n      appBar: ComComp.getAppBar(COLORS.SERIES_THEME_COLOR, STRING_NAME.SERIES_MOVIE),\n      body: CustomScrollView(\n        shrinkWrap: false,\n        slivers: <Widget>[\n          makeHeader(STRING_NAME.MOVIE),\n          Container(\n            child: FutureBuilder(\n                future: Services.getMovies(),\n                initialData: [],\n                builder: (context, snapshot) {\n                  //if (snapshot.connectionState == ConnectionState.done) {\n                    return ComComp.sliverGridMovies(snapshot, movieGridClicked);\n                  //} else {\n                  //  ComComp.circularProgress(COLORS.SERIES_THEME_COLOR);\n                 // }\n                }),\n          ),\n\n          makeHeader(STRING_NAME.SERIES),\n          Container(\n            child: FutureBuilder(\n                future: Services.getSeries(),\n                initialData: [],\n                builder: (context, snapshot) {\n                  //if (snapshot.connectionState == ConnectionState.done) {\n                    return ComComp.sliverGridSeries(snapshot, seriesGridClicked);\n                  //} else {\n                  //  ComComp.circularProgress(COLORS.SERIES_THEME_COLOR);\n                  //}\n                }),\n          ),\n        ],\n      ),\n    );\n  }\n\n  setLoading(bool loading) {\n    setState(() {\n      isHomeDataLoading = loading;\n    });\n  }\n\n  fetch() {setLoading(true);}\n}\n\nSliverPersistentHeader makeHeader(String headerText) {\n  return SliverPersistentHeader(\n    pinned: true,\n    delegate: _SliverAppBarDelegate(\n      minHeight: 60.0,\n      maxHeight: 130.0,\n      child: Container(\n        //color: COLORS.COMPLY,\n          color: COLORS.CRAFT_THEME_COLOR,\n          child: Center(\n            child: Text(headerText,\n              style: TextStyle(\n                  fontFamily: \'Chewy\', fontWeight: FontWeight.w500,\n                  color: Colors.white, fontSize: 32, letterSpacing: 2.0),\n            ),\n          )\n      ),\n    ),\n  );\n}\n\n\n\nclass _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {\n  _SliverAppBarDelegate({\n    @required this.minHeight,\n    @required this.maxHeight,\n    @required this.child,\n  });\n\n  final double minHeight;\n  final double maxHeight;\n  final Widget child;\n  @override\n  double get minExtent => minHeight;\n  @override\n  double get maxExtent => math.max(maxHeight, minHeight);\n  @override\n  Widget build(\n      BuildContext context,\n      double shrinkOffset,\n      bool overlapsContent)\n  {\n    return SizedBox.expand(child: child);\n  }\n  @override\n  bool shouldRebuild(_SliverAppBarDelegate oldDelegate) {\n    return maxHeight != oldDelegate.maxHeight;\n  }\n}\n\nmovieGridClicked(BuildContext context, CellModel model) {\n  // Grid Click\n      Navigator.push(context,\n          MaterialPageRoute(\n              builder: (context) => VideoPlayerScreen(model.title, model.url)));\n  //SnackBar Msg:\n  //Scaffold.of(context).showSnackBar(new SnackBar(content: Text(model.title),));\n}\n\nseriesGridClicked(BuildContext context, SeriesModel model) {\n  // Grid Click\n      Navigator.push(context,\n          MaterialPageRoute(\n              builder: (context) => EpisodeScreen(model.id.toString(), model.title)));\n  //SnackBar Msg:\n  //Scaffold.of(context).showSnackBar(new SnackBar(content: Text(model.title),));\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

comcomp.dart

\n\n
static SliverGrid sliverGridMovies (AsyncSnapshot snapshot, Function gridClicked){\n    var values = snapshot.data;\n\n    return SliverGrid(\n      delegate: SliverChildBuilderDelegate(\n            (BuildContext context, int index) {\n          return GestureDetector(\n            child: Cell(COLORS.SERIES_THEME_COLOR, values[index]),\n            onTap: () => gridClicked(context, values[index]),\n          );\n        },\n        childCount: values == null ? 0 : values.length,\n      ),\n      gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(\n        maxCrossAxisExtent: 300.0,\n        mainAxisSpacing: 5.0,\n        crossAxisSpacing: 5.0,\n        childAspectRatio: 1.0,\n      ),\n    );\n  }\n
Run Code Online (Sandbox Code Playgroud)\n\n

错误:

\n\n
I/flutter (21918): \xe2\x95\x90\xe2\x95\x90\xe2\x95\xa1 EXCEPTION CAUGHT BY RENDERING LIBRARY \xe2\x95\x9e\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nI/flutter (21918): The following assertion was thrown during performLayout():\nI/flutter (21918): SliverGeometry is not valid: The "maxPaintExtent" is less than the "paintExtent".\nI/flutter (21918): The maxPaintExtent is 177.5, but the paintExtent is 612.0. By definition, a sliver can\'t paint more\nI/flutter (21918): than the maximum that it can paint!\nI/flutter (21918): The RenderSliver that returned the offending geometry was:\nI/flutter (21918):   RenderSliverGrid#7ddfe relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT\nI/flutter (21918):   creator: SliverGrid \xe2\x86\x90 FutureBuilder<List<dynamic>> \xe2\x86\x90 Container \xe2\x86\x90 Viewport \xe2\x86\x90\nI/flutter (21918):   IgnorePointer-[GlobalKey#8bde6] \xe2\x86\x90 Semantics \xe2\x86\x90 Listener \xe2\x86\x90 _GestureSemantics \xe2\x86\x90\nI/flutter (21918):   RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#55565] \xe2\x86\x90 Listener \xe2\x86\x90 _ScrollableScope\nI/flutter (21918):   \xe2\x86\x90 _ScrollSemantics-[GlobalKey#062a8] \xe2\x86\x90 \xe2\x8b\xaf\nI/flutter (21918):   parentData: paintOffset=Offset(0.0, 0.0) (can use size)\nI/flutter (21918):   constraints: SliverConstraints(AxisDirection.down, GrowthDirection.forward,\nI/flutter (21918):   ScrollDirection.forward, scrollOffset: 379.7, remainingPaintExtent: 612.0, overlap: 60.0,\nI/flutter (21918):   crossAxisExtent: 360.0, crossAxisDirection: AxisDirection.right, viewportMainAxisExtent: 612.0,\nI/flutter (21918):   remainingCacheExtent: 1112.0 cacheOrigin: -250.0 )\nI/flutter (21918):   geometry: SliverGeometry(scrollExtent: 177.5, paintExtent: 612.0, maxPaintExtent: 177.5,\nI/flutter (21918):   hasVisualOverflow: true, cacheExtent: 1112.0)\nI/flutter (21918):   currently live children: 0 to 1\n\nI/flutter (21918)\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nI/flutter (21918): Another exception was thrown: SliverGeometry is not valid: The "maxPaintExtent" is less than the "paintExtent".\nI/chatty  (21918): uid=10250(com.globaltoons.globaltoons_mobile) 1.ui identical 1 line\nI/flutter (21918): Another exception was thrown: SliverGeometry is not valid: The "maxPaintExtent" is less than the "paintExtent".\nD/ViewRootImpl@93b5099[MainActivity](21918): ViewPostIme pointer 0\nD/ViewRootImpl@93b5099[MainActivity](21918): ViewPostIme pointer 1\nD/ViewRootImpl@93b5099[MainActivity](21918): ViewPostIme pointer 0\n
Run Code Online (Sandbox Code Playgroud)\n

小智 0

我遇到过同样的问题。

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

然后在“工具”选项卡下单击“flutter”,然后单击“flutter clean”,然后单击“flutter Upgrade”

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