颤振:在I / flutter(26461)中找不到路由RouteSettings(“ / HairServices-product-detail”,1)的生成器:_WidgetsAppState

时间:2020-11-01 21:42:02

标签: flutter

我在一个名为shop all的页面内创建了带有标签栏的类别,当我访问这些类别时,它工作正常,但是当我点击产品以查看其详细信息时,它向我显示了我上面提到的错误,是否存在一种解决方法?

ps:我在main.dart中添加了所有路由,但仍然存在相同的问题

   

class HairServicesPdtItem extends StatelessWidget {
  final String title;
  final String imag;
  final double price;

  const HairServicesPdtItem({Key key, this.title, this.imag, this.price})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    final pdt = Provider.of<Product>(context);
    final cart = Provider.of<Cart>(context);
    final wish = Provider.of<Wishe>(context);
    return GestureDetector(
      onTap: () {
        Navigator.of(context)
            .pushNamed(HairServicesDetailPage.routeName, arguments: pdt.id); //from here i called the detail page
        
            
      },
      child: SingleChildScrollView(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.symmetric(vertical: 5),
              child: Container(
                padding: EdgeInsets.all(0),
                height: 140,
                width: 140,
                decoration: BoxDecoration(
                  image: DecorationImage(
                 image: AssetImage(imag),
                    fit: BoxFit.cover,
                  ),
                  borderRadius: BorderRadius.circular(2),
                ),
                child: GridTile(
                  child: Image.asset(imag),
                  footer: GridTileBar(
                    leading: IconButton(
                      alignment: Alignment.bottomLeft,
                      icon: Icon(
                        Icons.favorite,
                        color: Colors.black,
                      ),
                      onPressed: () {
                        Scaffold.of(context).showSnackBar(SnackBar(
                          duration: Duration(seconds: 2),
                          content:
                              Text(' Item Successfully Added To Your Wishlist!'),
                                backgroundColor: HexColor("#D48C76"),
                        ));
                        wish.addItem(pdt.id, pdt.title, pdt.price, pdt.img);
                      },
                    ),
                    title: Text(''),
                    trailing: IconButton(
                      alignment: Alignment.bottomRight,
                      icon: Icon(
                        Icons.shopping_cart,
                        color: Colors.black,
                      ),
                      onPressed: () {
                        Scaffold.of(context).showSnackBar(SnackBar(
                          duration: Duration(seconds: 2),
                          content:
                              Text(' Item Successfully Added To Your Cart!'),
                                 backgroundColor: HexColor("#D48C76"),
                        ));
                        cart.addItem(pdt.id, pdt.title, pdt.price, pdt.img);
                      },
                    ),
                    backgroundColor: Colors.white70,
                  ),
                ),
              ),
            ),
            Padding(
              padding: const EdgeInsets.symmetric(vertical: 2),
              child: Text(
                title,
                textAlign: TextAlign.center,
                style:
                    TextStyle(color: Colors.black, fontWeight: FontWeight.w400),
              ),
            ),
            Text("${price} AED",
                style: TextStyle(
                  color: Colors.red,
                  fontWeight: FontWeight.w900,
                )),
          ],
        ),
      ),
    );
  }
}

路由:

import 'package:./screens/HairServices_offers.dart';
import 'package:./screens/HairServices_pdt_detail.dart';

void main() => runApp(
    MaterialApp(debugShowCheckedModeBanner: false, home: Notification()));

class Notification extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [

        ChangeNotifierProvider.value(value: Products_HairServices()),

        ChangeNotifierProvider.value(value: Cart()),
        ChangeNotifierProvider.value(value: Wishe()),
        ChangeNotifierProvider.value(
          value: Orders(),
        )
      ],
      child: MaterialApp(
          debugShowCheckedModeBanner: false,
          home: MyHomePage(),
          routes: {
          
            CartScreen.routeName: (ctx) => CartScreen(),
            WishList.routeName: (ctx) => WishList(),
       
            HairServicesDetailPage.routeName: (ctx) => HairServicesDetailPage(),
    
            
            HairServicesOffers.routeName: (ctx) => HairServicesOffers(),
      
          }),
    );
  }
}

1 个答案:

答案 0 :(得分:0)

问题实际上出在主文件中。您的主文件中有2个MaterialApp()小部件,情况并非如此。

尝试像这样删除MaterialApp()小部件之一:

import 'package:./screens/HairServices_offers.dart';
import 'package:./screens/HairServices_pdt_detail.dart';

void main() => runApp(Notification()); // I removed the MaterialApp() widget that was here.

class Notification extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [

        ChangeNotifierProvider.value(value: Products_HairServices()),

        ChangeNotifierProvider.value(value: Cart()),
        ChangeNotifierProvider.value(value: Wishe()),
        ChangeNotifierProvider.value(
          value: Orders(),
        )
      ],
      child: MaterialApp(
          debugShowCheckedModeBanner: false,
          home: MyHomePage(),
          routes: {
      
            CartScreen.routeName: (ctx) => CartScreen(),
           WishList.routeName: (ctx) => WishList(),
   
            HairServicesDetailPage.routeName: (ctx) => HairServicesDetailPage(),

        
            HairServicesOffers.routeName: (ctx) => HairServicesOffers(),
  
          }),
    );
  }
}