Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception ao invocar calcPrecoPrazo #5

Open
mon1eiro opened this issue Apr 23, 2021 · 1 comment
Open

Exception ao invocar calcPrecoPrazo #5

mon1eiro opened this issue Apr 23, 2021 · 1 comment

Comments

@mon1eiro
Copy link

---------------------------------------------------------Classe Calculadora------------------------------------------------------------

import 'package:sigepweb/sigepweb.dart';

class Calculadora {


  final sigepweb = Sigepweb(contrato: SigepContrato.semContrato());

  Future<void> calcFrete() async{
    final calcPrecoPrazo = await sigepweb.calcPrecoPrazo(
      cepOrigem: '01021200',
      cepDestino: '69911470',
      valorPeso: 1,
      formatoEncomenda: FormatoEncomenda.caixa,
      comprimento: 18,
      largura: 13,
      altura: 9
    );

    for (final item in calcPrecoPrazo) {
      print("${item.nome}: R\$ ${item.valor}");
    }
  }
}

----------------------------------------------------------------Método Main-------------------------------------------------------------

import 'package:flutter/material.dart';
import 'package:frete_correios/calculadora.dart';

void main() {
  runApp(MyApp());

  Calculadora calculadora = Calculadora();

  calculadora.calcFrete();
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Frete Correios'),
        centerTitle: true,
      ),
      body: Container(),
    );
  }
}

------------------------------------------------------------------------Run-----------------------------------------------------------------

Performing hot restart...
Syncing files to device sdk gphone x86...
Restarted application in 4.201ms.

======== Exception caught by widgets library =======================================================
The following assertion was thrown building MyApp:
No MediaQuery widget ancestor found.

Scaffold widgets require a MediaQuery widget ancestor.
The specific widget that could not find a MediaQuery ancestor was: Scaffold
dirty
state: ScaffoldState#912c9(lifecycle state: initialized, tickers: tracking 2 tickers)
The ownership chain for the affected widget is: "Scaffold ← MyApp ← [root]"

No MediaQuery ancestor could be found starting from the context that was passed to MediaQuery.of(). This can happen because you have not added a WidgetsApp, CupertinoApp, or MaterialApp widget (those widgets introduce a MediaQuery), or it can happen if the context you use comes from a widget above those widgets.

The relevant error-causing widget was:
MyApp file:///C:/Users/corre/Desktop/Projetos/frete_correios/lib/main.dart:6:10
When the exception was thrown, this was the stack:
#0 debugCheckHasMediaQuery. (package:flutter/src/widgets/debug.dart:219:7)
#1 debugCheckHasMediaQuery (package:flutter/src/widgets/debug.dart:234:4)
#2 MediaQuery.of (package:flutter/src/widgets/media_query.dart:820:12)
#3 ScaffoldState.didChangeDependencies (package:flutter/src/material/scaffold.dart:2820:50)
#4 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4725:11)
...

E/flutter (22460): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: Erro interno do package. Por favor considere abrir uma questão em https://github.com/marcobraghim/sigepweb/issues
E/flutter (22460): Mensagem da exception foi: DioError [DioErrorType.DEFAULT]: Bad state: Insecure HTTP is not allowed by platform: http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx/CalcPrecoPrazo?nCdEmpresa=08082650&sDsSenha=564321&nCdServico=04014%2C04510&sCepOrigem=01021200&sCepDestino=69911470&nVlPeso=1.0&nCdFormato=1&nVlComprimento=20&nVlAltura=20&nVlLargura=20&nVlDiametro=0&sCdMaoPropria=N&nVlValorDeclarado=0.0&sCdAvisoRecebimento=N&StrRetorno=xml&nIndicaCalculo=3
E/flutter (22460): #0 _HttpClient._openUrl (dart:_http/http_impl.dart:2434:7)
E/flutter (22460): #1 _HttpClient.openUrl (dart:_http/http_impl.dart:2341:7)
E/flutter (22460): #2 DefaultHttpClientAdapter.fetch (package:dio/src/adapters/io_adapter.dart:35:40)
E/flutter (22460): #3 DioMixin._dispatchRequest (package:dio/src/dio.dart:922:46)
E/flutter (22460):
E/flutter (22460): #4 Future.any.onValue (dart:async/future.dart)
E/flutter (22460):
E/flutter (22460):
E/flutter (22460): #0 Sigepweb.calcPrecoPrazo (package:sigepweb/src/core.dart:166:7)
E/flutter (22460):
E/flutter (22460): #1 Calculadora.calcFrete (package:frete_correios/calculadora.dart:10:28)
E/flutter (22460):
E/flutter (22460):

======== Exception caught by widgets library =======================================================
The following assertion was thrown building MyApp:
No MediaQuery widget ancestor found.

Scaffold widgets require a MediaQuery widget ancestor.
The specific widget that could not find a MediaQuery ancestor was: Scaffold
dirty
state: ScaffoldState#585e0(lifecycle state: initialized, tickers: tracking 2 tickers)
The ownership chain for the affected widget is: "Scaffold ← MyApp ← [root]"

No MediaQuery ancestor could be found starting from the context that was passed to MediaQuery.of(). This can happen because you have not added a WidgetsApp, CupertinoApp, or MaterialApp widget (those widgets introduce a MediaQuery), or it can happen if the context you use comes from a widget above those widgets.

The relevant error-causing widget was:
MyApp file:///C:/Users/corre/Desktop/Projetos/frete_correios/lib/main.dart:6:10
When the exception was thrown, this was the stack:
#0 debugCheckHasMediaQuery. (package:flutter/src/widgets/debug.dart:219:7)
#1 debugCheckHasMediaQuery (package:flutter/src/widgets/debug.dart:234:4)
#2 MediaQuery.of (package:flutter/src/widgets/media_query.dart:820:12)
#3 ScaffoldState.didChangeDependencies (package:flutter/src/material/scaffold.dart:2820:50)
#4 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4725:11)
...

@mon1eiro
Copy link
Author

mon1eiro commented Apr 26, 2021

Encontrei uma solução para o problema com o http. Adicionando em androidmanifest.xml o seguinte:

<application android:usesCleartextTraffic="true>"

Mas não sei qual seria a implicação no momento da publicação nas lojas...

documentação

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant