Flutter-Setstat有时会更新,有时不会

问题描述

每次我单击圆圈时,它都会更新颜色和颜色。但是,有时,它总是回到以前的状态,因为银行已更新为正确的状态..我的代码有什么问题?就像不同步一样。每次我单击圆圈时,它都会更新存储库并更新颜色。但是有时候它总是会回到以前的状态。 我的代码怎么了?

import 'package:bets_online/Api/remover_reservas_api.dart';
import 'package:bets_online/Api/validar_compra_api.dart';
import 'package:bets_online/pages/ConfirmarPage.dart';
import 'package:bets_online/Widgets/alerta.dart';
import 'package:bets_online/Model/numero.dart';
import 'package:bets_online/Api/numeros_api.dart';
import 'package:bets_online/Api/selecionar_api.dart';
import 'package:flutter/material.dart';

class NumeroPage extends StatefulWidget {
  final int idPremio;
  int selected;

  NumeroPage({this.idPremio,this.selected});

  @override
  _NumeroPageState createState() => _NumeroPageState();
}

class _NumeroPageState extends State<NumeroPage> {
  @override
  Future<bool> _onWillPop() async {
    await Remover.removerReservas();
    return true;
  }

  Widget build(BuildContext context) {
    return WillPopScope(
        onWillPop: _onWillPop,child: Scaffold(
          appBar: AppBar(
            title: Text("Escolha os Números",style: TextStyle(color: Colors.white,fontSize: 25)),centerTitle: true,backgroundColor: Colors.deepPurple[300],),body: _body(),));
  }

  _body() {

    Future<List<Numero>> numeros = NumeroApi.getNumeros(widget.idPremio);
    return FutureBuilder(

      future: numeros,builder: (context,snapshot) {
        if (snapshot.hasError) {
          return Center(
              child: Text("Erro,verifique com o administrador do Sistema.",style: TextStyle(fontSize: 25,color: Colors.redAccent)));
        }
        if (!snapshot.hasData) {
          return Center(child: CircularProgressIndicator());
        }
        List<Numero> numeros = snapshot.data;

        return _listView(numeros);
      },);
  }
  _onClickSelecionar(BuildContext context,int idNumero,int idPremio,String latitude,String logintude) async {
    var numero = await SelecionarNumero.Selecionar(
        idNumero,idPremio,latitude,logintude);

    if (numero.error) {
      alert(context,numero.message,"Erro");
    }
  }

  _listView(numeros) {
    return Scaffold(
      body: GridView.builder(
        shrinkWrap: true,itemCount: numeros.length,gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisSpacing: 5,mainAxisSpacing: 5,crossAxisCount: 5,itemBuilder: (BuildContext context,int index) => GestureDetector(
          child: Container(
            decoration: BoxDecoration(
                color: numeros[index + 0].status == "RE" &&
                        numeros[index + 0].numeroUsuarioAtual == 'N'
                    ? Colors.grey[400]
                    : numeros[index + 0].status == "PG"
                        ? Colors.lightBlueAccent
                        : (numeros[index + 0].numeroUsuarioAtual == 'S' &&
                                numeros[index + 0].status == "RE")
                            ? Colors.yellowAccent
                            : Colors.green,borderRadius: new BorderRadius.circular(100.0),boxShadow: [
                  BoxShadow(
                    offset: const Offset(2.0,2.0),blurRadius: 4.0,spreadRadius: 1.0,]),child: Center(
              child: Text('${index + 1}',style:
                      new TextStyle(fontWeight: FontWeight.bold,fontSize: 24)),onTap: () {
            setState(() {
              _listView(numeros);
              Numero p = numeros[index + 0];

              _onClickSelecionar(
                  context,p.idNumero,p.idPremio,'1111','222222');
              return _listView(numeros);
            });
          },primary: false,padding: const EdgeInsets.all(10),bottomNavigationBar: Padding(
        padding: EdgeInsets.all(0.0),child: RaisedButton(
          onPressed: () {
            _navegaConfirmar(context);
          },padding: EdgeInsets.all(15.0),color: Colors.redAccent,textColor: Colors.white,child: Text('Comprar',style: TextStyle(
                  color: Colors.white,fontSize: 25.0,fontWeight: FontWeight.bold)),);
  }


  _navegaConfirmar(BuildContext context) async {
    var validar = await Valida.validarCompra(widget.idPremio);
    if (validar.error) {
      alert(context,validar.message,"Erro");
    } else {
      Navigator.push(
        context,MaterialPageRoute(
            builder: (context) => ConfirmarPage(idPremio: widget.idPremio)),);
    }
  }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...