放置多提供商后如何修复死代码错误?
How to fix the dead code error after placing multiproviders?
错误信息:
Try removing the code, or fixing the code before it so that it can be
reached.
我该如何解决这个问题?我尝试了所有我不能做的事情。
I need the MaterialApp to appear because it is part of the application
and I cannot remove this part of the code because it is the main
screen of the application.
错误图片;
Dead Code
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import './views/products_overview_screen.dart';
import './utils/app_routes.dart';
import './views/product_detail_screen.dart';
import './providers/products.dart';
import './providers/cart.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
Provider<Products>(create: (_) => Products()),
],
builder: (context, child) {
final cart = context.watch<Cart>();
return Text('$cart');
},
);
MaterialApp(
title: 'Minha Loja',
theme: ThemeData(
primarySwatch: Colors.purple,
accentColor: Colors.deepOrange,
fontFamily: 'Lato'),
home: ProductsOverviewSceen(),
routes: {
AppRoutes.PRODUCT_DETAIL: (ctx) => ProductDetailsScreen(),
},
);
}
}
改成这样:
return Text('$cart');
},
child: MaterialApp
.
.
.
.
) // Add the parenthesis at the end.
错误信息:
Try removing the code, or fixing the code before it so that it can be reached.
我该如何解决这个问题?我尝试了所有我不能做的事情。
I need the MaterialApp to appear because it is part of the application and I cannot remove this part of the code because it is the main screen of the application.
错误图片;
Dead Code
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import './views/products_overview_screen.dart';
import './utils/app_routes.dart';
import './views/product_detail_screen.dart';
import './providers/products.dart';
import './providers/cart.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
Provider<Products>(create: (_) => Products()),
],
builder: (context, child) {
final cart = context.watch<Cart>();
return Text('$cart');
},
);
MaterialApp(
title: 'Minha Loja',
theme: ThemeData(
primarySwatch: Colors.purple,
accentColor: Colors.deepOrange,
fontFamily: 'Lato'),
home: ProductsOverviewSceen(),
routes: {
AppRoutes.PRODUCT_DETAIL: (ctx) => ProductDetailsScreen(),
},
);
}
}
改成这样:
return Text('$cart');
},
child: MaterialApp
.
.
.
.
) // Add the parenthesis at the end.