You have how to get a list<Items> items;

Asked

Viewed 30 times

0

Code:

class ListarPedido {
  int numero;
  String localEntrega;
  String dataHora;
  String formaPagamento;
  List<Itens> itens;

  ListarPedido({
    this.numero,
    this.localEntrega,
    this.dataHora,
    this.formaPagamento,
    this.itens,
  });

  ListarPedido.fromJson(Map<String, dynamic> json) {
    numero = json['numero'];
    localEntrega = json['local_entrega'];
    dataHora = json['data_hora'];
    formaPagamento = json['forma_pagamento'];
    if (json['Itens'] != null) {
      itens = new List<Itens>();
      json['Itens'].forEach((v) {
        itens.add(new Itens.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['numero'] = this.numero;
    data['local_entrega'] = this.localEntrega;
    data['data_hora'] = this.dataHora;
    data['forma_pagamento'] = this.formaPagamento;
    if (this.itens != null) {
      data['Itens'] = this.itens.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class Itens {
  String itemUid;
  String qtde;
  String valor;
  String valorTotal;
  String descrProduto;
  String tamanho;
  String textoOpc;

  Itens({
    this.itemUid,
    this.qtde,
    this.valor,
    this.valorTotal,
    this.descrProduto,
    this.tamanho,
    this.textoOpc,
  });

  Itens.fromJson(Map<String, dynamic> json) {
    itemUid = json['item_uid'];
    qtde = json['qtde'];
    valor = json['valor'];
    valorTotal = json['valor_total'];
    descrProduto = json['descr_produto'];
    tamanho = json['tamanho'];
    textoOpc = json['texto_opc'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['item_uid'] = this.itemUid;
    data['qtde'] = this.qtde;
    data['valor'] = this.valor;
    data['valor_total'] = this.valorTotal;
    data['descr_produto'] = this.descrProduto;
    data['tamanho'] = this.tamanho;
    data['texto_opc'] = this.textoOpc;
    return data;
  }
}

apirest code via post, where I want to get List Items:

import 'dart:convert';
import 'package:cardapiomonitor/api/listar_pedido.dart';
import 'package:http/http.dart' as http;
import '../functions/fn_utils.dart';

class ListarPedidoApi {
  static Future<List<ListarPedido>> getListarPedido() async {
    var url = "http://192.168.1.12/api/ws_acoes.php";
    String lppeduuid = prefs.getString("PedUuid");

    var response = await http.post(
      url,
      headers: <String, String>{
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
      },
      body: <String, String>{
        'pedido': lppeduuid,
        'requisicao': 'LISTARPEDIDO',
      },
    );

    List listaResponseLP = json.decode(response.body);

    final listarpedidos = List<ListarPedido>();

    for (Map mapLP in listaResponseLP) {
      ListarPedido lp = ListarPedido.fromJson(mapLP);
      listarpedidos.add(lp);
    }

    return listarpedidos;
  }
}

  • I believe you need to be clearer with your goal in the question. Is there a get? Yes, there is. Get access to values? Get a request? Your own method that makes a post, it’s called getListarPedido, so you’re no longer doing a 'get'? Be clearer on the problem. https://pt.meta.stackoverflow.com/questions/8089/guia-survivor%C3%aancia-do-sopt-vers%C3%a3o-short? cb=1

  • Yeah, I’m already doing a get, but I’m not getting the get of the items.

  • Then I think it would be a get access to the values I would need?

  • In your "API" you need to create a route to return only the items... Ai in your application make the call from that route.

  • Could you tell me how I can start creating this route, have some example here at stackoverflow?

  • Face this must be done in your API "http://192.168.1.12/api/ws_acoes.php", this is no longer related to Flutter and I have no content to indicate.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.