when iam trying to navigate to anew page no errors occur but still nothing happens i dont no if on tap is the problem or the void function , please help me thanks
import 'package:flutter/material.dart';
import 'meals_category_screen.dart';
class CategoryItem extends StatelessWidget {
final String title;
final Color color;
const CategoryItem(this.title, this.color);
void selectCategory (BuildContext ctx){
Navigator.of(ctx).push(MaterialPageRoute(builder: (_){
return const MealsCategoryScreen();
}));
}
@override
Widget build(BuildContext context) {
return InkWell(
onTap:()=> selectCategory,
splashColor: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(15),
child: Container(
padding: const EdgeInsets.all(15),
child: Text(title,style: Theme.of(context).textTheme.subtitle1,),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [color.withOpacity(.7), color],
begin: Alignment.topLeft,
end: Alignment.bottomRight),
borderRadius: BorderRadius.circular(15),
),
),
);
}
}
CodePudding user response:
try. onTap: selectCategory
it might solve your issue
CodePudding user response:
Try using onTap: () => selectCategory(context)
instead.
CodePudding user response:
You are passing a pointer to your function to your onTap property, not calling your function.
For calling your function properly, you should do this:
onTap: () => selectCategory(context);
CodePudding user response:
You need to passing the values like this
selectCategory(BuildContext ctx) {
Navigator.of(ctx).pushNamed(CategoryMealsScreen.routeName,
arguments: {'id': id, 'title': title});
}