Reputation: 51
Widget cusSearchBar = Text("Supplier");
is there any way to pass the context to cusSearchBar. Help will be appreciated.
Upvotes: 1
Views: 1908
Reputation: 1331
Extract as Widget
class CusSearchBar extends StatelessWidget {
const CusSearchBar({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Text('Supplier');
}
}
Upvotes: 3
Reputation: 332
Widget cusSearchBar(BuildContext context){
return Text("Supplier");
}
Upvotes: 2
Reputation: 7601
try this:
Widget cusSearchBar = _cusSearchBar(context, 'Supplier');
Widget _cusSearchBar(BuildContext context, String txt) {
//use of context...
return Text(txt);
}
Upvotes: 2