我正在從另一個專案中學習,當我嘗試實施它時,出現以下錯誤:
錯誤:無法將引數型別“IconData”分配給引數型別“Widget”。
有什么幫助嗎?
我的代碼如下:
class HomeScreen extends StatelessWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: kBackground,
body: CustomScrollView(
slivers: [
SliverAppBar(
expandedHeight: 150,
elevation: 0,
pinned: true,
stretch: true,
toolbarHeight: 80,
backgroundColor: Colors.white,
leading: IconButton(
onPressed: (){
Navigator.pushNamed(context, '/signUp');
},
icon: Icons.person_outline,
),
),
],
),
);
}
}
uj5u.com熱心網友回復:
icon: Icons.person_outline,
這Icons.person_outline是型別IconData
您需要在IconWidget 中使用它。
icon: const Icon(Icons.person_outline),
uj5u.com熱心網友回復:
正確的方法是:
icon: Icon(Icons.person_outline)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/401084.html
上一篇:如何遍歷每個專案并在螢屏上呈現?
