简体   繁体   English

Flutter:如果我想导航到详细信息页面,我会在 flutter 中收到无效参数错误

[英]Flutter: i get invalid argument(s) Error in flutter if i want to navigate to detail page

I want to navigate to detail page.我想导航到详细信息页面。 But i get invalid argument error.但我得到无效的参数错误。 In detail page, i try to get detail information from my online server.在详细页面中,我尝试从我的在线服务器获取详细信息。 If i click on Hot reload button in android studio, the error disappear.如果我单击 android 工作室中的热重载按钮,错误就会消失。 Please, How can i do to fix this error?请问,我该如何解决这个错误? Screenshoot of error错误截图

the error log:错误日志:

════════ (2) Exception caught by widgets library ═══════════════════════════════════════════════════
Invalid argument(s): The source must not be null
The relevant error-causing widget was: 
  DetailArticlePage file:///C:/Users/abiboo/FlutterProject/projectname/lib/miledoo_widget/home.dart:515:39
//home.dart
return new Container(
          margin: EdgeInsets.symmetric(vertical: 8.0),
          height: 240.0,
          child: ListView.builder(
              scrollDirection: Axis.horizontal,
              itemCount: articledata.length,
              itemBuilder: (BuildContext context,int index) {
                return Padding(
                  padding: EdgeInsets.all(4),
                  child: InkWell(
                    onTap: (){
                      Navigator.push(
                          context,
                          new MaterialPageRoute(
                              builder: (context) =>
                                  DetailArticlePage(int.parse(articledata[index].idArt), articledata[index].designation)));
                    },
                    child: Container(
                      decoration: BoxDecoration(
                        boxShadow: [
                          BoxShadow(

This is a piece of code for detail page who contain a method to get detail informaation from server这是详细页面的一段代码,其中包含从服务器获取详细信息的方法

//detailpage.dart
import 'package:cached_network_image/cached_network_image.dart';
import 'package:f_miledoo/miledoo_widget/detail_boutique_page.dart';
import 'package:f_miledoo/miledoo_widget/panier_page.dart';
import 'package:f_miledoo/models/detail_article_models.dart';
import 'package:f_miledoo/models/panier_models.dart';
import 'package:f_miledoo/shared/constants.dart';
import 'package:f_miledoo/utils/database_helper.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../localisation_internationnalisation/localisation.dart';
import 'dart:async';
import 'package:http/http.dart' as http;
import 'dart:convert';

class DetailArticlePage extends StatefulWidget{
  final int id_art;
  final String art_desgnation;
  DetailArticlePage(this.id_art, this.art_desgnation);

  DetailArticlePages createState() => DetailArticlePages();
}

class DetailArticlePages extends State<DetailArticlePage> {

  DatabaseHelper helper = DatabaseHelper();
  PanierModel _panier = new PanierModel.withempty();

  final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();



  int qtecompter = 1;
  double prixTotal = 0.0;
  String aAfficher = "";

  int taillePanier = 0;


  String idArt;
  String designation;
  String descrip;
  String prixUnit;
  String prixUnit2;
  String qteStock;
  String idBou;
  String lienPhoto;
  String nomBou;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    getpanierTaille();
    this.getRecapArticleData(widget.id_art, widget.art_desgnation);

  }

  getpanierTaille() async => taillePanier = await helper.getCount();





  getRecapArticleData(int id_article, String nom_article) async {
    final response = await http.get(BASE + "xxxxxxx?id_art="+ id_article.toString() +"&nom_art="+ nom_article);
    if (response.statusCode == 200) {
      final jsonResponse = json.decode(response.body);

      TheDetailData myData = new TheDetailData.fromJson(jsonResponse);
      for (var i = 0; i < myData.articledetail.list_recap_article.length; i++) {
        idArt = myData.articledetail.list_recap_article[i].idArt;
        designation = myData.articledetail.list_recap_article[i].designation;
        descrip = myData.articledetail.list_recap_article[i].descrip;
        prixUnit = myData.articledetail.list_recap_article[i].prixUnit;
        prixUnit2 = myData.articledetail.list_recap_article[i].prixUnit2;
        qteStock = myData.articledetail.list_recap_article[i].qteStock;
        lienPhoto = myData.articledetail.list_recap_article[i].lienPhoto;
        idBou = myData.articledetail.list_recap_article[i].idBou;

        print("id_art = " + idArt + " designation = " + designation +
            "  prixUnit2 = " + prixUnit2 + "  Qté = " + qteStock);
      }

    } else {
      throw Exception("Failed to load Data");
    }
  }

  Future<List<ListArtMemeCate>> _getSameArticleData(int id_article, String nom_article) async {
    final response = await http.get(BASE + "xxxxxxx?id_art="+ id_article.toString() +"&nom_art="+ nom_article);
    if (response.statusCode == 200) {
      final jsonResponse = json.decode(response.body);

      TheDetailData myData = new TheDetailData.fromJson(jsonResponse);
      List<ListArtMemeCate> datas = [];

      for (var i = 0; i < myData.articledetail.list_art_meme_cate .length; i++) {
        datas.add(myData.articledetail.list_art_meme_cate[i]);
      }
      return datas;
    } else {
      throw Exception("Failed to load Data");
    }
  }

  @override
  Widget build(BuildContext context) {

    int localStockQte = int.parse(qteStock);
    double localPrixUnit2 = double.parse(prixUnit2.toString());



    Widget article_afficher333 = FutureBuilder(
      future: _getSameArticleData(widget.id_art, widget.art_desgnation),
      builder: (context, snapshot) {
        //if(snapshot.data != null){
        if (snapshot.hasData) {
          List<ListArtMemeCate> articledata = snapshot.data;
          return new Container(
            child: GridView.count(
              shrinkWrap: true,
              crossAxisCount: 2,
              childAspectRatio: 0.7,
              padding: EdgeInsets.only(top: 8, left: 6, right: 6, bottom: 12),
              children: List.generate(articledata.length, (index){
                return Container(
                  child: Card(
                    clipBehavior: Clip.antiAlias,
                    child: InkWell(
                      onTap: () {
                            Navigator.push(
                            context,
                                new MaterialPageRoute(
                                    builder: (context) =>
                                    DetailArticlePage(int.parse(articledata[index].idArt) , articledata[index].designation)));
                      },
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          SizedBox(
                            height: (MediaQuery.of(context).size.width / 2 - 40),
                            width: double.infinity,
                            child: CachedNetworkImage(
                              fit: BoxFit.cover,
                              imageUrl: BASEIMAGES+articledata[index].lienPhoto,
                              placeholder: (context, url) => Center(
                                  child: CircularProgressIndicator()
                              ),
                              errorWidget: (context, url, error) => new Icon(Icons.image),
                            ),
                          ),
                          Padding(
                            padding: const EdgeInsets.only(top: 2.0),
                            child: ListTile(
                              title: Text((() {
                                if(articledata[index].designation.length >12){
                                  return "${articledata[index].designation.substring(0, 12)}...";}

                                return "${articledata[index].designation}";
                              })(), style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15.0, fontFamily: "Questrial")), 
                              subtitle: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: <Widget>[
                                  Row(
                                    children: <Widget>[
                                      Padding(
                                        padding: const EdgeInsets.only(top: 2.0, bottom: 1),
                                        child: Text(articledata[index].prixUnit2+" F CFA", style: TextStyle(
                                            color: Theme.of(context).accentColor,
                                            fontWeight: FontWeight.w700,
                                            fontFamily: 'Questrial'
                                        )),
                                      ),
                                    ],
                                  ),

                                ],
                              ),
                            ),
                          )
                        ],
                      ),
                    ),
                  ),
                );
              }),

            ),
          );
        } else if (snapshot.hasError) {
          return Container(
            child: Center(
              child: Text(
                  "Erreur de chargement. Verifier votre connexion internet"),
            ),
          );
        }
        return new Center(
          child: CircularProgressIndicator(),
        );
      },
    );


    setState(() {
      _panier.nom_article = designation;
      _panier.prixUnit2 = double.parse(prixUnit2);
      _panier.image_article = lienPhoto;
      _panier.prixTot = qtecompter*double.parse(prixUnit2);
      _panier.quantite = qtecompter ;
      _panier.id_article = int.parse(idArt);
    });

    void _incrementeQte(){
      setState((){
        if(qtecompter >= localStockQte){
          qtecompter = localStockQte;
        }
        qtecompter++;
      });
    }
    void _decrementeQte(){
      setState((){
        if(qtecompter <=1){
          qtecompter = 1;
        }else{
          qtecompter--;
        }
      });
    }

    String _getPrixTotal(){
      setState((){
        prixTotal = qtecompter*localPrixUnit2;
            aAfficher = prixTotal.toString();
      });
      return aAfficher;
    }
void _ajouterPanier() async {
      //s.addToCart(widget.article);
      var result = await helper.addCart(_panier);
      var result3 = await helper.getCount();
      /*int result;
      result = await helper.addCart(_panier);
      if(result != 0)
        print('STATUS Panier Save Successfully');*/
    }


    return Scaffold(
      key: _scaffoldKey,
      appBar: AppBar(
        title: Text("designation", style:  TextStyle(color: Colors.white),),
        iconTheme: new IconThemeData(color: Colors.white),
        actions: <Widget>[

          Stack(
            children: <Widget>[
              IconButton(
                icon: Icon(Icons.shopping_cart, color: Colors.white, ),
                onPressed: () {
                  //showAlertDialog(context);
                  Navigator.push(context, new MaterialPageRoute(builder: (context) => PanierPage()));
                },
              ),
              Container(
                  width: 25,
                  height: 25,
                  decoration: BoxDecoration(
                    color: Colors.red,
                    borderRadius: BorderRadius.circular(30),
                  ),
                  alignment: Alignment.center,
                  child: Text(taillePanier.toString(),
                    style: TextStyle(
                        color: Colors.white,
                        fontWeight: FontWeight.bold,
                        fontSize: 12
                    ),)
              ),
            ],
          ),
        ],
      ),
      body: new ListView(
        children: <Widget>[
          new Container(
            height: 240,
            child: new Hero(tag: lienPhoto, child: new Material(
              child: InkWell(
                child: new Image.network(
                    BASEIMAGES + lienPhoto,
                    fit: BoxFit.cover),
              ),
            )),
          ),
          new Container(
            child: new Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: <Widget>[
                Padding(
                  padding: const EdgeInsets.only(top: 10,left: 5),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      new Text(designation.toString(), style: new TextStyle(fontSize: 20.0, color: Colors.black, fontFamily: 'Questrial'),),
                      ],
                  ),
                ),
                SizedBox(height: 10.0),
                Padding(
                  padding: const EdgeInsets.only(left: 280),
                  child: new Text(prixUnit2.toString()+" F CFA", style: new TextStyle(fontSize: 15.0, color: Colors.black54, fontFamily: 'Questrial', fontWeight: FontWeight.bold),),
                ),

                SizedBox(height: 10.0),
                Padding(
                  padding: const EdgeInsets.only(left: 20, right: 20, bottom: 10),
                  child: new Text(descrip.toString(), style: new TextStyle(fontSize: 15.0, color: Colors.grey, fontFamily: 'Questrial'),),
                ),
                SizedBox(height: 10.0),
                new Container(
                  height: 100,

              child: Column(
                children: <Widget>[
                  Container(
                    height: 1.0,
                    color: Colors.grey,
                  ),
                  Padding(
                    padding: const EdgeInsets.only(left: 25, right: 25, top: 20),
                    child: new Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Text(AppLocalizations.of(context)
                        .translate('_QUANTITY'), style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15, fontFamily: 'Questrial'),),
                        Text(AppLocalizations.of(context)
                            .translate('_TOTAL_PRICE'), style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15, fontFamily: 'Questrial'), ),
                      ],
                    ),
                  ),

                  Padding(
                    padding: const EdgeInsets.only(left: 10, right: 25),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        new Row(
                          children: <Widget>[
                            new IconButton(
                              icon: Icon(Icons.remove_circle_outline, color: Colors.amber, ),
                              onPressed: _decrementeQte,
                            ),
                            new Text("$qtecompter"),
                            new IconButton(
                              icon: Icon(Icons.add_circle_outline, color: Colors.amber, ),
                              onPressed: _incrementeQte,
                            ),
                          ],
                        ),
                        new Text(_getPrixTotal()+" F CFA", style: new TextStyle(fontSize: 20.0, color: Colors.grey),),
                      ],
                    ),
                  ),
                  Container(
                    height: 1.0,
                    color: Colors.grey,
                  ),
                ],
              ),
            ),
            //articleMemeCategorie()
          ],
        ),
      ),
      Padding(
        padding: const EdgeInsets.only(top: 10, left: 25, ),
        child: Text(AppLocalizations.of(context)
            .translate('_ITEMS_OF_SAME_QUATEGORY'), style: TextStyle(fontFamily: 'Questrial', fontSize: 15, fontWeight: FontWeight.bold),),
      ),
      article_afficher333,
    ],
  ),
    bottomNavigationBar: new Container(
      color: Colors.white,
      child: new Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Expanded(child: new MaterialButton(
            onPressed: (){showAlertDialog(context);},
            child: new Row(
              //crossAxisAlignment: CrossAxisAlignment.end,
              children: <Widget>[
                IconButton(
            //widget.article
                  icon: Icon(Icons.store, color: Colors.white,),
                  onPressed: () {
                    //showAlertDialog(context);
                    Navigator.push(
                        context,
                        new MaterialPageRoute(
                            builder: (context) =>
                                DetailBoutiquePage(int.parse(idBou)))); },
                ),
              ],
            ),
            color: Color(0xFFFFC23A),
          ),),

          Expanded(
            flex: 2,
            child: new MaterialButton(
            onPressed: (){
              _ajouterPanier();
            },
            child: new Container(
              child: new Row(
                children: <Widget>[
                  IconButton(
                    icon: Icon(Icons.add_shopping_cart, color: Colors.white,),
                  ),
                  Text(AppLocalizations.of(context)
    .translate('_ADD_TO_CART'), style: TextStyle(color: Color(0xFFFFFFFF)))
                ],
              ),
            ),
            color: Color(0xFFFFC23A),
          ),),

          Expanded(child: new MaterialButton(
            onPressed: (){showAlertDialog(context);},
            child: new Text(AppLocalizations.of(context)
                .translate('_BUY_NOW'), style: TextStyle(color: Color(0xFFFFFFFF)),),
            color: Color(0xFFFFC23A),
          ),),
        ],
      ),
    )

);
  }

}

Without seeing your full detail page and error log it is difficult to tell exactly what your error is.如果没有看到完整的详细信息页面和错误日志,就很难准确判断您的错误是什么。

From the information you have given it sounds like you are trying to retrieve data from an Http request, and then use that information for the display of your page.从您提供的信息看来,您正在尝试从 Http 请求中检索数据,然后使用该信息显示您的页面。 Have you tried using a FutureBuilder in the detail page?您是否尝试过在详细信息页面中使用 FutureBuilder? This will allow you to display a page while waiting for the data from the server, and will then display the data from the server once it has been retrieved.这将允许您在等待来自服务器的数据时显示一个页面,然后在检索到来自服务器的数据后显示该数据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想要一个使用 Deep Link 导航到特定 Flutter 页面的示例 - I want a sample that uses Deep Link to navigate to a specific Flutter page Flutter 中的参数无效 - Invalid argument(s) in Flutter (颤抖)我怎样才能在课堂上争论? - (flutter) How can I get argument in class? 我想在flutter中将数据发送到一页并显示另一页 - I Want to send data to one page and display another page in flutter flutter -i 设置后台任务时出错(PluginRegistry 无法转换为 FlutterEngine ...) - flutter -i get error when i want to set background task (PluginRegistry cannot be converted to FlutterEngine ...) Flutter来自ADB的意外故障:无效参数:源不得为空在设备上启动应用程序时出错 - Flutter Unexpected failure from adb: Invalid argument(s): The source must not be null Error launching application on device 运行时出现Flutter项目,显示错误无效参数:源不得为null - Flutter project when run showing Error Invalid argument(s): The source must not be null Flutter WillPopScope对我来说正常工作,但是当我导航或推回到同一页面时,它不起作用 - Flutter WillPopScope works normally for me but when I navigate or push back to the same page it does not work 无效参数:在 URI flutter getconnect 中未指定主机 - Invalid argument(s): No host specified in URI flutter getconnect Flutter - ArgumentError(无效参数:URI 文件中未指定主机:///) - Flutter - ArgumentError (Invalid argument(s): No host specified in URI file:///)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM