I/flutter (25517): No Material widget found.
I/flutter (25517): ListTile widgets require a Material widget ancestor.
I/flutter (25517): In material design, most widgets are conceptually "printed" on a sheet of material. In Flutter's
I/flutter (25517): material library, that material is represented by the Material widget. It is the Material widget
I/flutter (25517): that renders ink splashes, for instance. Because of this, many material library widgets require that
I/flutter (25517): there be a Material widget in the tree above them.
I/flutter (25517): To introduce a Material widget, you can either directly include one, or use a widget that contains
I/flutter (25517): Material itself, such as a Card, Dialog, Drawer, or Scaffold.
I/flutter (25517): The specific widget that could not find a Material ancestor was:
I/flutter (25517):   ListTile

简而言之:

使用了Material 风格的widget 就需要Scaffold作为根布局

什么是Material 风格的widget,比如

  • AppBar
  • BottomAppBar
  • FloatingActionButton
  • Drawer
  • SnackBar
  • BottomSheet
  • BottomNavigationBar
  • ListTile
  • 等等

需要Scaffold作为根布局,意为用Scaffold包裹起来即可

return Scaffold(
      appBar: AppBar( ),
      bottomNavigationBar: BottomNavigationBar( ),
      floatingActionButton: FloatingActionButton( ),
      drawer: Drawer(),
      .....
    );

Logo

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐