Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 如何在颤振中从一个dart文件访问另一个dart文件的静态列表? 处境_List_Flutter - Fatal编程技术网

List 如何在颤振中从一个dart文件访问另一个dart文件的静态列表? 处境

List 如何在颤振中从一个dart文件访问另一个dart文件的静态列表? 处境,list,flutter,List,Flutter,firstScreen.dart中的静态列表如下 static List<Shoe> shoeBank = [ Shoe(b: "Red Shoe", i: "assets/nikeShoeProduct1.jpg", q: 0), Shoe(b: "White Shoe", i: "assets/nikeShoeProduct2.jpg", q: 0) ]; 现在我想使用seco

firstScreen.dart中的静态列表如下

static List<Shoe> shoeBank = [
    Shoe(b: "Red Shoe", i: "assets/nikeShoeProduct1.jpg", q: 0),
    Shoe(b: "White Shoe", i: "assets/nikeShoeProduct2.jpg", q: 0)
  ]; 
现在我想使用
secondScreen.dart
文件中的
shoeBank
列表。 如何做到这一点

而且 我想使用shoeBank的值,同时在
secondScreen.dart中将参数传递给下面的组件
CheckOutItems

CheckoutItems(
addedToCartNumber:use of shoeBank Over here ,
checkOutScreenProductImage:use of shoeBank Over here,
shoesName:use of shoeBank Over here; 

如何操作?

您可以使用
FirstScreen.shoeBank
SecondScreen
中访问
静态shoeBank

我在下面添加了一个示例:

第二屏

class SecondScreen扩展了无状态小部件{
//使用类名访问静态列表
List shoeList=FirstScreen.shoeBank;
@凌驾
小部件构建(构建上下文){
//使用这里的列表
返回签出项目(
//数量
addedToCartNumber:shoeList[0]。数量,
//形象
checkOutScreenProductImage:shoeList[0]。图像,
//鞋店
鞋店名称:鞋店[0]。品牌,
);
}
}
第一屏

class FirstScreen扩展了无状态小部件{
//鞋子银行静态列表在这里
静态列表shoeBank=[
鞋子(b:“红鞋”,i:“资产/nikeShoeProduct1.jpg”,q:0),
鞋子(b:“白色鞋子”,i:“资产/nikeShoeProduct2.jpg”,q:0)
]; 
@凌驾
小部件构建(构建上下文){
返回容器(
);
}
}

firstScreen.shoeBank。在使用List shoeList=FirstScreen.shoeBank时,是否还有其他需要查找的内容;表示您是如何使用的?谢谢,使用时它工作得非常好
List shoeList=FirstScreen.shoeBank它给出了一个错误,例如,没有为类型“FirstScreen”定义getter“shoeBank”,您可以更新您的问题以显示有关此错误的更多详细信息吗?我提供的代码一切正常。现在它工作了,我必须在FirstScreen中制作一个getter,当使用此`返回CheckoutItems(//quantity addedToCartNumber:shoeList[0]。quantity,//image CheckOutScreen产品image:shoeList[0]。image,//shoe branch shoesName:shoeList[0]。brand,);`为什么会出现这种错误?请参阅下面的注释。Wit用于访问
shoeBank
列表的
第一个元素。确保您的
shoeBank
列表中包含项目。
CheckoutItems(
addedToCartNumber:use of shoeBank Over here ,
checkOutScreenProductImage:use of shoeBank Over here,
shoesName:use of shoeBank Over here; 
 class SecondScreen extends StatelessWidget {

   // access the static list using the class name
   List<Shoe> shoeList = FirstScreen.shoeBank;

   @override
   Widget build(BuildContext context) {
     // use the list here
     return CheckoutItems(
       // quantity
       addedToCartNumber: shoeList[0].quantity,
       // image
       checkOutScreenProductImage: shoeList[0].image,
       // shoe branch
       shoesName: shoeList[0].brand,
     );
   }
 }

 class FirstScreen extends StatelessWidget {
   // shoe bank static list here
   static List<Shoe> shoeBank = [
    Shoe(b: "Red Shoe", i: "assets/nikeShoeProduct1.jpg", q: 0),
    Shoe(b: "White Shoe", i: "assets/nikeShoeProduct2.jpg", q: 0)
  ]; 

   @override
   Widget build(BuildContext context) {
     return Container(
       
     );
   }
 }