首页 > 解决方案 > 单击凸起的按钮失败,没有任何错误

问题描述

我的应用程序中有一个非常奇怪的错误。当我尝试单击“PARIER”按钮时,它绝对没有任何作用,我不明白为什么。我调用了 Prono_Match() 但它根本不起作用,我没有语法错误,它什么也没做。我试过叫另一个页面,但它是一样的。为什么它完全忽略 Prono_Match 的调用???非常非常奇怪:(

我的代码:

import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'dart:async';
import 'menu_member.dart';
import 'globals.dart' as globals;
import 'appbar_draw.dart';
import 'package:awesome_dialog/awesome_dialog.dart';
import 'package:intl/intl.dart';
import 'prono_match.dart';

// Create a Form widget.
class Affiche_Matchs extends StatefulWidget {
  @override

  _Affiche_Matchs_State createState() {
    return _Affiche_Matchs_State();
  }
}

// Create a corresponding State class.
// This class holds data related to the form.

class _Affiche_Matchs_State extends State<Affiche_Matchs> {
  @override

  bool load=false;
  bool visible=false;
  String idmatch="";
  String prono="";

  List<String> radioValues = [];
  Future<List<Match>> grid;

  Future <List<Match>> Liste_Match_Display() async {
    // SERVER LOGIN API URL
    var url = 'https://www.easytrafic.fr/game_app/display_matchs.php';

    var data = {
      'id_membre': globals.id_membre,
    };

    var data_encode = jsonEncode(data);
    // Starting Web API Call.
    var response = await http.post(url,body: data_encode,headers: {'content-type': 'application/json','accept': 'application/json','authorization': globals.token});

    // Getting Server response into variable.

    var jsondata = json.decode(response.body);

    List<Match> Matchs = [];
    var i=0;
    for (var u in jsondata) {
      i=i+1;
      Match match = Match(u["id"],u["equipe1"],u["equipe2"],u["dated"],u["heured"]);
      Matchs.add(match);
      radioValues.add("");
    }
    return Matchs;
  }

  void initState() {
    super.initState();
    grid = Liste_Match_Display();
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
    Container(
    decoration: BoxDecoration(
      gradient: LinearGradient(
      begin: Alignment.topLeft,
      end: Alignment.bottomRight,
      colors: <Color>[
        Colors.blue[300],Colors.blue[400]
      ],
    ),
    ),
    ),
      Scaffold(
        appBar: drawappbar(true),
        backgroundColor: Colors.transparent,
        drawer: new DrawerOnly(className: Affiche_Matchs()),
        body:
            Center(
            child : Column(
              children: <Widget>[
                Container(
          height: MediaQuery.of(context).size.height*0.8,
          width: MediaQuery.of(context).size.width,
          child:
          FutureBuilder(
            future: grid,
            builder: (BuildContext context, AsyncSnapshot snapshot) {
          switch (snapshot.connectionState) {
          case ConnectionState.waiting: return new Center(child: new CircularProgressIndicator(),);
          default:
          if(snapshot.hasError) {
          return new Center(child: new Text('Error: ${snapshot.error}'),);
          }
          else {
          List<Match> values = snapshot.data;
          if (values.isEmpty) {
          return Container(
          child: Center(
          child: Text("Aucun match disponible !!!",style: TextStyle(color: Colors.white))
          )
          );
          }
          else {
            Match lastitem;
            lastitem=values[0];
            int i=0;
            return ListView.builder(itemCount: values.length,itemBuilder: (_,index) {
                          bool header = lastitem.date_debut !=
                              values[index].date_debut;
                          lastitem = values[index];
                          var parsedDate = DateTime.parse(values[index].date_debut);
                          final formatter = new DateFormat('dd/MM/yyyy');
                          var dat = formatter.format(parsedDate);
                          return Column(
                            children: [
                              (header || index == 0)
                                  ?
                          Container(
                            height: 30,
                            margin: EdgeInsets.only(top:10),
                            width: MediaQuery.of(context).size.width,
                            decoration: BoxDecoration(
                                border: Border.all(
                                  color: Colors.blue[700],
                                  width: 2,
                                ),
                                color: Colors.blue[700]
                            ),
                            child : new Text(dat,textAlign: TextAlign.center,style: TextStyle(fontSize: 18.0,fontWeight: FontWeight.w500,color: Colors.white),),
                          )// here// display header
                                  :
                                  Container(),
                                  Container(
                                  margin: EdgeInsets.only(top:20,bottom:20),
                                  child: Center(
                                  child: Text(values[index].heure_debut,style: TextStyle(color: Colors.white)),
                                  ),
                                  ),
                                  Container(
                                    margin: const EdgeInsets.only(bottom:10),
                                    child: Row(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                  crossAxisAlignment: CrossAxisAlignment.center,
                                  children: [
                                    Container(
                                      child: Text(values[index].equipe1+" - "+values[index].equipe2,style: TextStyle(fontSize:10,color: Colors.white)),
                                    ),
                            ]
                  ),
                                  ),
                              Container(
                                  margin: const EdgeInsets.only(left:5),
                                  child: RaisedButton(
                                    color: Colors.green,
                                    textColor: Colors.white,
                                    padding: EdgeInsets.fromLTRB(5, 5, 5, 5),
                                    child: Text('PARIER'),
                                    onPressed: () {
                                        idmatch=values[index].id;
                                        print(idmatch);
                                        setState(() {
                                        visible=true;
                                        });
                                        Prono_Match(idmatch: idmatch);
                                    },
                                  ),
                                ),
                  ]
                          );
                        }
                );
          }
          };
          };
          }
                          ),
                ),
      ]
    )
            )
            )
    ]
    );
        }

}

class Match {

  final String id;
  final String equipe1;
  final String equipe2;
  final String date_debut;
  final String heure_debut;

  const Match(this.id,this.equipe1, this.equipe2,this.date_debut,this.heure_debut);

}

标签: flutter

解决方案


我猜你在按下按钮时试图显示 Prono_Match 页面,尽管这不是你在颤动中调用页面的方式,而是这样做:

onPressed: () {
      idmatch=values[index].id;
      print(idmatch);
      setState(() {
         visible=true;
      });
     Navigator.push(context,MaterialPageRoute(builder: (context)=>Prono_Match(idmatch: idmatch),),
   );
 },


推荐阅读