颤振某些按钮在某些设备上不起作用

时间:2020-10-07 22:58:22

标签: android flutter button

大家好,我的应用程序中有一个简单的+-按钮,我在lenove p2,note 4,k20 pro上进行了测试,效果很好,但在OnePlus 5T OxygenOs V10和Android V10上无论如何我都无法正常工作当我单击它时它不起作用,就像一个空按钮,这是代码

  void showPricingSheet(context , article){
  List<int> quantities = [];
  List<int> serviceIds = [];
  List<double> totalPrices = [];
  double currentTotalPrice = 0.0;
  int servicesLength;
  //theses variables will be used to store values locally then send them to server
  Future<List<Prices>> _prices = _fetchPrices(article['id']);
  bool alreadyExc = false;

  showModalBottomSheet(
      isDismissible: false,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(
          top: Radius.circular(20),
        ),
      ),
      context: context,
      builder: (BuildContext context){
        var responsivenessController = ResponsivenessController(context);
        return StatefulBuilder(
          builder: (BuildContext context , setState){
            return FutureBuilder<List<Prices>>(
                future: _prices,
                builder: (context , snapshot){
                  if(snapshot.hasData){
                    List<Prices> price = snapshot.data;
                    if(alreadyExc == false){
                      // initializing the list with the length provided
                      servicesLength = price.length;
                      for(int i = 0; i < price.length; i++){
                        quantities.add(0);
                        serviceIds.add(price[i].serviceId);
                        totalPrices.add(0);
                      }
                      alreadyExc = true;
                    }
                    return Container(
                        padding: EdgeInsets.all(30),
                        child: Stack(
                          children: <Widget>[
                            ListView(
                              children: <Widget>[
                                Column(
                                  children: <Widget>[
                                    articleName(article),
                                        Column(
                                          children: List.generate(price.length, (index) =>
                                            Row(
                                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                                children: <Widget>[
                                                  Expanded(
                                                    child: Container(
                                                      padding: EdgeInsets.all(10),
                                                      child: Text(
                                                        translator.currentLanguage == 'ar' ?
                                                        '${price[index].serviceNameAr}'
                                                            :'${price[index].serviceNameEn}',
                                                        overflow: TextOverflow.ellipsis,
                                                        style: TextStyle(
                                                          fontSize: responsivenessController.bodyFont1,
                                                        ),
                                                      ),
                                                    ),
                                                  ),
                                                  Text('${price[index].price}' ,
                                                      style: TextStyle(
                                                        fontSize: responsivenessController.bodyFont1,
                                                      ),
                                                    ),
                                                  Container(
                                                    child: Row(
                                                      children: <Widget>[
                                                // the problem is in this section 
                                                //
                                                //
                                                //
                                                //
                                                         IconButton(
                                                          onPressed: (){
                                                            setState(() {
                                                              double oldPrice = (quantities[index] * price[index].price).toDouble();
                                                              quantities[index] = quantities[index] + 1;
                                                              double newPrice = (quantities[index] * price[index].price).toDouble();
                                                              totalPrices[index] = newPrice.toDouble();
                                                              currentTotalPrice = (currentTotalPrice - oldPrice).toDouble();
                                                              currentTotalPrice = (currentTotalPrice + newPrice).toDouble();
                                                            });
                                                          },
                                                          icon: Icon(Icons.add , color: Color(0xffff9900),),
                                                        ),
                                                        Text(
                                                            '${quantities[index]}'
                                                        ),
                                                        IconButton(
                                                          onPressed: (){
                                                            setState(() {
                                                              if(quantities[index] > 0){
                                                                double oldPrice = (quantities[index] * price[index].price).toDouble();
                                                                quantities[index] = quantities[index] - 1;
                                                                double newPrice = (quantities[index] * price[index].price).toDouble();
                                                                totalPrices[index] = newPrice.toDouble();
                                                                currentTotalPrice = (currentTotalPrice - oldPrice).toDouble();
                                                                currentTotalPrice = (currentTotalPrice + newPrice).toDouble();
                                                              }
                                                              DoNothingAction();
                                                            });
                                                          },
                                                          icon: Icon(Icons.remove , color: Color(0xffff9900),),
                                                        ),
                                                   //ends here 
                                                   //
                                                   //
                                                   //
                                                      ],
                                                    ),
                                                  )
                                                ],
                                              )
                                        )
                                    )
                                  ],
                                ),
                              ],
                            ),
                            Align(
                              alignment: Alignment.bottomCenter,
                              child: Container(
                                width: DeviceInformation(context).width,
                                child: RaisedButton(
                                  onPressed: currentTotalPrice <= 0.0 ? null
                                    : (){
                                    for(int i = 0; i < servicesLength; i++){
                                        savePurchase(
                                          article['id'],
                                          serviceIds[i],
                                          quantities[i],
                                          totalPrices[i],
                                        );
                                    }
                                    return _customStoredSuccessfully(context);
                                  },
                                  shape: RoundedRectangleBorder(
                                      borderRadius: BorderRadius.circular(10)),
                                  color: Color(0xffff9900),
                                  child: Text(
                                    translator.currentLanguage == 'ar' ?
                                    'اضافة ${currentTotalPrice.toStringAsFixed(2)} الى الطلب'
                                        : 'Add ${currentTotalPrice.toStringAsFixed(2)} To Order',
                                    style: TextStyle(color: Colors.white),
                                  ),
                                ),
                              ),
                            )
                          ],
                        )
                    );
                  }
                  if(snapshot.hasError){
                    return SomeThingWrongHappened();
                  }
                  return LoadingIndicator();
                },
            );
          },
        );
      }
  );
}

如您所见,它的简单按钮将采用商品价格并将其添加或从旧值中扣除,然后将其存储到db,但是问题不在api中,正如我提到的+-按钮在几乎所有设备上,它都能正常工作,但在5t上,由于某些原因,它无法正常工作

注意:我没有5t手机,这就是为什么我无法将其连接到PC进行调试

0 个答案:

没有答案