When I put "child: Text(...)" inside the Expanded class, it tells me that child isn't defined and I can't figure out what to do.
class _AppBarButton extends StatelessWidget {
final String title;
final Function onTap;
const _AppBarButton({
Key key,
this.title,
this.onTap,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: Expanded(
child: Text( // this is where the child isn't defined.
title,
style: const TextStyle(
color: Colors.white,
fontSize: 16.0,
fontWeight: FontWeight.w600,
),
),
),
);
}
}
You are getting the error due to the Expanded widget.
Typically, Expanded widgets are placed directly inside Flex widgets.
Either remove the Expanded Widget or Wrap the Expanded Widget with a Column or Row like the following code :
class _AppBarButton extends StatelessWidget {
final String title;
final Function onTap;
const _AppBarButton({
Key key,
this.title,
this.onTap,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: Column(
children: [
Expanded(
child: Text(
title,
style: const TextStyle(
color: Colors.black,
fontSize: 16.0,
fontWeight: FontWeight.w600,
),
),
),
],
),
);
}
}