Reputation: 2489
I have a SettingsTile
as below, it is no any problems,
SettingsSection(
title: 'System',
tiles: [
SettingsTile(
title: 'Reset',
leading: Icon(Icons.clear_all_sharp),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () {
Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) => LoginPage()));
},
),
But if I changed it to code as below:
SettingsSection(
title: 'System',
tiles: [
_optionPush('Reset', Icons.clear_all_rounded, Icon(Icons.keyboard_arrow_right), LoginPage, context),
Widget _optionPush(title, leading, trailing, func, context) {
return SettingsTile(
title: title,
leading: leading,
trailing: trailing,
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) => func(),
),
);
},
);
}
I got error type 'IconData' is not a subtype of type 'Widget'
, what can I do next?
Upvotes: 1
Views: 1079
Reputation: 2218
you forgot to wrap the iconData with the Icon()
widget
SettingsSection(
title: 'System',
tiles: [
_optionPush('Reset', Icons.clear_all_rounded, Icon(Icons.keyboard_arrow_right), LoginPage, context),
Widget _optionPush(title, leading, trailing, func, context) {
return SettingsTile(
title: title,
leading: Icon(leading),
trailing: Icon(trailing),
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) => func(),
),
);
},
);
}
Upvotes: 1
Reputation: 6029
You forgot to wrap Icon() widget to icon data. Please see below.
SettingsSection(
title: 'System',
tiles: [
_optionPush('Reset', Icon(Icons.clear_all_rounded, Icon(Icons.keyboard_arrow_right), LoginPage, context),
Upvotes: 1