Flutterando / slidy

CLI package manager and template for Flutter
https://pub.dev/packages/slidy
Apache License 2.0
806 stars 101 forks source link

Redirecionar para outra tela quando a mensagem for enviada - Flutter/Dart #221

Closed LukeGMs closed 3 years ago

LukeGMs commented 3 years ago

Esse post está escondido. Você deletou esse post 5 horas atrás. Fechada. Essa pergunta é fora de escopo e não está atualmente aceitando respostas. Apesar de ser sobre programação, esta pergunta não parece atender os critérios mínimos de qualidade e detalhamento para um site de perguntas e respostas. As perguntas aqui precisam ser para problemas específicos, práticos ou conceituais sobre algoritmos, ferramentas e técnicas de programação e desenvolvimento de software. Melhore a pergunta.

Fechada 9 horas atrás.

(Feedback privado para você)

Olá, boa tarde?! Pessoal, estou com um problema para redirecionar o usuário para uma outra tela se a mensagem for envia. Tipo, no meu código tem dois botões onde é apresentado a opção de editar a mensagem (o botão sim) e a opção de não editar (o botão não) a mensagem para que desta forma a pessoa seja direcionada para uma nova pagina se o envio for positivo. Mas não estou conseguindo fazer isso acontecer, já tentei tornar "bool" a função enviaMensagem, mas sem êxito, me ajudem com essa questão por favor!?

Essa é a minha tela onde esta todo o código de recebimento dos textos dos dos inputs de texto, e também o botão ( botão Não) onde quero adicionar a função de validar de se a função enviarMensagem foi executado com sucesso ( foi enviada) e retornar uma outra tela.

import 'dart:io';
import 'package:flutter/services.dart';
import 'package:animated_text_kit/animated_text_kit.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:mailer/mailer.dart';
import 'package:mailer/smtp_server/gmail.dart';
import 'package:ouvidoria_mvl/Agradecimentos.dart';
import 'package:animated_button/animated_button.dart';

// ignore: must_be_immutable
class PaginadeBoasVindasAN extends StatelessWidget {
  String _nomeAn;
  String _localAn;
  String _problemaAn;
  File _imagem;

  PaginadeBoasVindasAN(
    this._nomeAn,
    this._localAn,
    this._problemaAn,
    this._imagem,
  );

  // Aqui vamos criar o e-mail - smtp

  enviaMensagem() async {
    String username = '*****@gmail.com';
    String password = '*****';

    final smtpServer = gmail(username, password);
    // Use the SmtpServer class to configure an SMTP server:
    // final smtpServer = SmtpServer('smtp.domain.com');
    // See the named arguments of SmtpServer for further configuration
    // options.

    // Create our message.
    final message = Message()
      ..from = Address(_problemaAn, 'Ouvidoria Móvel')
      ..recipients.add('*****@gmail.com')
      ..ccRecipients.addAll(['destCc1@example.com', 'destCc2@example.com'])
      ..bccRecipients.add(Address('bccAddress@example.com'))
      ..subject = '$_localAn :: ${DateTime.now()}'
      ..text =
          'O munipe disse que a localização do problema é $_localAn, <bold> e o problema aboradado por ele foi $_problemaAn'
      ..attachments = _imagem as List<Attachment>;

    try {
      final sendReport = await send(message, smtpServer);
      print('Mensagem enviada: ' + sendReport.toString());
    } on MailerException catch (e) {
      print('Mensagem não enviada.');
      for (var p in e.problems) {
        print('Problema: ${p.code}: ${p.msg}');
      }
    }

    var connection = PersistentConnection(smtpServer);

    await connection.send(message);
    await connection.close();
  }

// AQUI ACABA A CONFIGURAÇÃO DOS APP

  //a Funcação abaixo bloqueia o giro de tela, permitindo assim que o app fique no modo vertical
  void blockgiro() {
    SystemChrome.setPreferredOrientations(
        [DeviceOrientation.portraitDown, DeviceOrientation.portraitUp]);
  }

  @override
  Widget build(BuildContext context) {
    blockgiro();
    return Stack(children: <Widget>[
      Scaffold(
        appBar: AppBar(
            automaticallyImplyLeading: false,
            centerTitle: true,
            title: Row(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                SizedBox(width: 20.0, height: 100.0),
                Text(
                  "Ouvidoria",
                  style: TextStyle(fontSize: 24.0),
                ),
                SizedBox(width: 20.0, height: 100.0),
                RotateAnimatedTextKit(
                    repeatForever: true,
                    isRepeatingAnimation: true,
                    duration: const Duration(milliseconds: 2000),
                    onTap: () {
                      print("");
                    },
                    text: ["Móvel", "Móvel", "Móvel"],
                    textStyle: TextStyle(fontSize: 24.0, fontFamily: "Horizon"),
                    textAlign: TextAlign.start),
              ],
            )),
        backgroundColor: Colors.white,
        body: SingleChildScrollView(
            padding: EdgeInsets.only(bottom: 20),
            child: Container(
                margin: EdgeInsets.all(10),
                color: Colors.transparent,
                child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      Container(
                          margin: EdgeInsets.only(
                            left: 1,
                            bottom: 10,
                            top: 10,
                          ),
                          padding: EdgeInsets.all(10),
                          height: 200,
                          decoration: BoxDecoration(
                              boxShadow: [
                                BoxShadow(
                                    blurRadius: 0,
                                    color: Colors.white,
                                    offset: Offset(0, 0))
                              ],
                              borderRadius: BorderRadius.circular(13),
                              color: Colors.white),
                          child:
                              Image.asset("Assets/image/enviando-loading.gif")),
                      Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Container(
                            padding: EdgeInsets.only(
                                bottom: 30, right: 1, left: 1, top: 20),
                          ),
                          Container(
                            margin: EdgeInsets.only(
                              left: 1,
                              bottom: 10,
                              top: 5,
                            ),
                            padding: EdgeInsets.all(10),
                            decoration: BoxDecoration(
                                boxShadow: [
                                  BoxShadow(
                                      blurRadius: 2,
                                      color: Colors.black54,
                                      offset: Offset(1, 1))
                                ],
                                borderRadius: BorderRadius.circular(13),
                                color: Colors.white),
                            child: Align(
                              alignment: Alignment.topLeft,
                              child: SizedBox(
                                width: 250.0,
                                child: TypewriterAnimatedTextKit(
                                  pause: Duration(minutes: 10),
                                  speed: Duration(milliseconds: 100),
                                  onTap: () {
                                    print("Tap Event");
                                  },
                                  text: ['A localização é essa: $_localAn'],
                                  textStyle: TextStyle(
                                      color: Colors.black,
                                      fontSize: 20.0,
                                      fontFamily: "Agne"),
                                  textAlign: TextAlign.start,
                                ),
                              ),
                            ),
                          ),
                          Container(
                              margin: EdgeInsets.only(
                                left: 1,
                                bottom: 10,
                                top: 10,
                              ),
                              padding: EdgeInsets.all(10),
                              decoration: BoxDecoration(
                                  boxShadow: [
                                    BoxShadow(
                                        blurRadius: 4,
                                        color: Colors.black54,
                                        offset: Offset(2, 2))
                                  ],
                                  borderRadius: BorderRadius.circular(13),
                                  color: Colors.white),
                              child: Align(
                                alignment: Alignment.topLeft,
                                child: SizedBox(
                                  width: 1000.0,
                                  child: TypewriterAnimatedTextKit(
                                      pause: Duration(minutes: 10),
                                      onTap: () {
                                        print("Tap Event");
                                      },
                                      text: [
                                        'Seu problema é: $_problemaAn',
                                      ],
                                      textStyle: TextStyle(
                                          color: Colors.black,
                                          fontSize: 20.0,
                                          fontFamily: "Agne"),
                                      textAlign: TextAlign.justify,
                                      curve: Curves.linear),
                                ),
                              )),
                          Container(
                            margin: EdgeInsets.all(10),
                            padding: EdgeInsets.all(10),
                            child: _imagem != null
                                ? Image.file(
                                    _imagem,
                                    fit: BoxFit.scaleDown,
                                  )
                                : Center(
                                    child: Text(
                                      'Capture uma foto',
                                      style: TextStyle(
                                          color: Colors.black,
                                          fontWeight: FontWeight.w400),
                                    ),
                                  ),
                            decoration: BoxDecoration(
                                boxShadow: [
                                  BoxShadow(
                                      blurRadius: 1,
                                      color: Colors.transparent,
                                      offset: Offset(1, 1))
                                ],
                                borderRadius: BorderRadius.circular(30),
                                color: Colors.transparent),
                          ),
                          Container(
                            padding: EdgeInsets.only(bottom: 20, top: 20),
                          ),

                          Row(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              TypewriterAnimatedTextKit(
                                  pause: Duration(minutes: 10),
                                  onTap: () {
                                    print("Decida abaixo");
                                  },
                                  text: [
                                    'Precisa editar sua mensagem?',
                                  ],
                                  textStyle: TextStyle(
                                      fontWeight: FontWeight.w600,
                                      color: Colors.lightBlueAccent,
                                      fontSize: 20.0,
                                      fontFamily: "Agne"),
                                  textAlign: TextAlign.center,
                                  curve: Curves.linear),
                            ],
                          ),

                          //INICIO DOS BOTOES SIM E NAO
                          Container(
                            padding: EdgeInsets.only(bottom: 50),
                          ),
                          Row(
                            mainAxisAlignment: MainAxisAlignment.center,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              Container(
                                margin: EdgeInsets.only(
                                    bottom: 2, top: 2, right: 55),
                                alignment: Alignment.centerLeft,
                                child: AnimatedButton(
                                  shape: BoxShape.rectangle,
                                  child: Text(
                                    'Sim',
                                    style: TextStyle(
                                      fontSize: 19,
                                      color: Colors.white,
                                      fontWeight: FontWeight.w500,
                                    ),
                                  ),
                                  onPressed: () {
                                    Navigator.pop(context);
                                  },
                                  width: 50,
                                  color: Colors.red[600],
                                  shadowDegree: ShadowDegree.dark,
                                  enabled: true,
                                ),
                              ),
                              //ACIMA SIM, ABAIXO NÃO
                              Container(
                                margin: EdgeInsets.only(
                                    bottom: 2, top: 2, left: 55),
                                alignment: Alignment.centerRight,
                                child: AnimatedButton(
                                  child: Text(
                                    'Não',
                                    style: TextStyle(
                                      fontSize: 19,
                                      color: Colors.white,
                                      fontWeight: FontWeight.w500,
                                    ),
                                  ),
                                  onPressed: () {
                                    Navigator.of(context).push(
                                        MaterialPageRoute(
                                            builder: (context) => bazingada()));
                                  },
                                  width: 50,
                                  color: Colors.green[600],
                                  shadowDegree: ShadowDegree.dark,
                                  enabled: true,
                                ),
                              )
                            ],
                          )
                        ],
                      ),
                      Container(
                        padding: EdgeInsets.only(bottom: 50),
                      ),
                    ]))),
      )
    ]);
  }
}
LukeGMs commented 3 years ago

Resolvido chamando o ShowDialog...