Coder Social home page Coder Social logo

Comments (10)

AndreHaueisen avatar AndreHaueisen commented on September 3, 2024

Hi @carnivash . One of your build functions is returning null. If you are trying to use Flushbar as the returned widget of a build function, please read the documentation because you are doing it wrong.

from flushbar.

carnivash avatar carnivash commented on September 3, 2024

I'm trying to show on the onpressed of a materialbutton:

MaterialButton(
onPressed: flushMessage.show(context),
minWidth: _screenWidth * 0.837,
height: _screenHeight * 0.09,
color: Color.fromARGB(255, 52, 92, 170),
textColor: Colors.white,
child: Text("entrar", style: FontStyles.loginButtonEnter,),
),

from flushbar.

AndreHaueisen avatar AndreHaueisen commented on September 3, 2024

onPressed receives a callback function (){}. Wrap the flushbar code like this

MaterialButton(
   onPressed: (){
      flushMessage.show(context);
   },
   minWidth: _screenWidth * 0.837,
   height: _screenHeight * 0.09,
   color: Color.fromARGB(255, 52, 92, 170),
   textColor: Colors.white,
   child: Text("entrar", style: FontStyles.loginButtonEnter,),
),

from flushbar.

carnivash avatar carnivash commented on September 3, 2024

I tried that, same error.

from flushbar.

AndreHaueisen avatar AndreHaueisen commented on September 3, 2024

Ok. I need more code. Paste your class here, please.

from flushbar.

carnivash avatar carnivash commented on September 3, 2024

Yes sir, here it goes:

import 'package:flushbar/flushbar.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:thinkseg/utils/font_styles.dart';
import 'package:flutter_villains/villain.dart';
import 'package:after_layout/after_layout.dart';
import 'package:thinkseg/utils/network_util.dart';


class LoginScreen extends StatefulWidget {
  @override
  _LoginScreenState createState() => _LoginScreenState();
}

class _LoginScreenState extends State<LoginScreen> with AfterLayoutMixin<LoginScreen> {

  FocusNode _focusPasswordTextField, _focusEmailTextField;
  double _marginHorizontalMainContainer, _marginVerticalMainContainer;
  bool _firstRender = true;
  bool _firstEnter = true;
  double _mainContainerBorderRadius = 12.0;
  Icon _errorIconEmail, _errorIconPassword;
  Color _borderEmailFieldColor = Color.fromARGB(255, 223, 227, 233);
  Color _borderPasswordFieldColor = Color.fromARGB(255, 223, 227, 233);
  Color _borderEmailFieldColorError = Colors.red;
  Color _borderPasswordFieldColorError = Colors.red;
  Color _actualEmailBorderColor;
  Color _actualPasswordBorderColor;

  TextEditingController _inputControllerEmail = TextEditingController();
  TextEditingController _inputControllerPassword = TextEditingController();
  
  NetworkUtil netUtil = NetworkUtil();

  Flushbar flushMessage = Flushbar(
    title: "Erro de autenticação",
    message: "Usuário ou senha inválidos!",
    flushbarPosition: FlushbarPosition.TOP,
    reverseAnimationCurve: Curves.decelerate,
    forwardAnimationCurve: Curves.elasticOut,
    duration: Duration(seconds: 3),
    icon: Icon(
      Icons.error,
      color: Colors.red,
    ),
    isDismissible: false,
    leftBarIndicatorColor: Colors.red,
  );



  @override
  void afterFirstLayout(BuildContext context) async {
    VillainController.playAllVillains(context);
    _firstRender = false;
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _errorIconEmail = null;
    _errorIconPassword = null;
    _actualEmailBorderColor = _borderEmailFieldColor;
    _actualPasswordBorderColor = _borderPasswordFieldColor;
    _focusEmailTextField = FocusNode();
    _focusPasswordTextField = FocusNode();
    _focusPasswordTextField.addListener(() {
      if(_focusEmailTextField.hasFocus || _focusPasswordTextField.hasFocus) {
        _animateOpenMainContainer();
      }
    });
    _focusEmailTextField.addListener(() {
      if(_focusEmailTextField.hasFocus || _focusPasswordTextField.hasFocus) {
        _animateOpenMainContainer();
      }
    });
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _focusPasswordTextField.dispose();
    _focusEmailTextField.dispose();
  }

  @override
  Widget build(BuildContext context) {

    double _screenHeight = MediaQuery.of(context).size.height;
    double _screenWidth = MediaQuery.of(context).size.width;

    if(_firstRender) {
      _marginHorizontalMainContainer = _screenWidth * 0.04;
      _marginVerticalMainContainer = _screenHeight * 0.10;
    }

    return SafeArea(
      child: Material(
        child: Stack(
          children: <Widget>[
            Container( // fundo azul escuro
              margin: EdgeInsets.all(0.0),
              color: Color.fromARGB(255, 48, 65, 96),
            ),
            Villain(
              animateEntrance: true,
              villainAnimation: VillainAnimation.fromBottom(
                relativeOffset: 1.0,
                from: Duration(milliseconds: 0),
                to: Duration(milliseconds: 1000),
                curve: Curves.elasticOut
              ),
              secondaryVillainAnimation: VillainAnimation.fade(),
              child: AnimatedContainer( // container branco arredondado
                curve: Curves.easeOut,
                duration: Duration(milliseconds: 300),
                margin: EdgeInsets.symmetric(horizontal: _marginHorizontalMainContainer, vertical: _marginVerticalMainContainer),
                decoration: ShapeDecoration(
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.all(Radius.circular(_mainContainerBorderRadius)),
                    ),
                    color: Colors.white),
                child: Column(
                  children: <Widget>[
                   Container(//primeira linha da coluna que possui o logo
                     decoration: BoxDecoration(
                       color: Colors.white,
                       borderRadius: BorderRadius.vertical(top: Radius.circular(_mainContainerBorderRadius)),
                       boxShadow: [
                         BoxShadow(
                           color: Color.fromARGB(20, 0, 0, 0),
                           blurRadius: 20.0,
                           offset: Offset(0.0, 15.0)
                         )
                       ]
                     ),
                     height: _screenHeight * 0.135,
                     alignment: Alignment.center,
                     child: SvgPicture.asset(
                       "assets/images/logo.svg",
                       height: _screenHeight * 0.389,
                       width: _screenWidth * 0.501,
                     ),
                   ),
                    Column(//coluna que contem o formulário
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        SizedBox(height: _screenHeight * 0.020,),//espaçamento entre o título e o container superior
                        Villain(
                          villainAnimation: VillainAnimation.scale(
                            fromScale: 1.2,
                            toScale: 1.0,
                            from: Duration(milliseconds: 500),
                            to: Duration(milliseconds: 700),
                          ),
                          secondaryVillainAnimation: VillainAnimation.fade(),
                          child: Text(
                            "Login",
                            style: FontStyles.loginTitle,
                          ),
                        ),
                        SizedBox(height: _screenHeight * 0.009,),//espaçamento entre o subtítulo e o título
                        Villain(
                          villainAnimation: VillainAnimation.scale(
                            fromScale: 1.2,
                            toScale: 1.0,
                            from: Duration(milliseconds: 600),
                            to: Duration(milliseconds: 800),
                          ),
                          secondaryVillainAnimation: VillainAnimation.fade(),
                          child: Text(
                            "Mesmo e-mail e senha do site 🙂",
                            style: FontStyles.loginLabel,
                          ),
                        ),
                        SizedBox(height: _screenHeight * 0.019,),//espaçamento entre a borda do campo email e o subtítulo
                        Villain(
                          villainAnimation: VillainAnimation.scale(
                            fromScale: 1.2,
                            toScale: 1.0,
                            from: Duration(milliseconds: 700),
                            to: Duration(milliseconds: 900),
                          ),
                          secondaryVillainAnimation: VillainAnimation.fade(),
                          child: Container(//borda do campo de email
                            padding: EdgeInsets.only(left: 15.0),
                            alignment: Alignment.center,
                            width: _screenWidth * 0.837,
                            height: _screenHeight * 0.09,
                            decoration: ShapeDecoration(
                              color: Colors.white,
                              shape: RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(4.0),
                              side: BorderSide(
                                  color: _actualEmailBorderColor,
                                  style: BorderStyle.solid,
                                  width: 1.0
                                )
                              ),
                            ),
                            child: TextField(//campo de email
                              focusNode: _focusEmailTextField,
                              style: FontStyles.loginLabel,
                              keyboardType: TextInputType.emailAddress,
                              textCapitalization: TextCapitalization.none,
                              textInputAction: TextInputAction.next,
                              controller: _inputControllerEmail,
                              onChanged: (String val) {
                                if(!_firstEnter) {
                                  validateEmail();
                                }
                              },
                              onSubmitted: (val) {
                                FocusScope.of(context).requestFocus(_focusPasswordTextField);
                              },
                              decoration: InputDecoration(
                                labelText: "E-mail",
                                labelStyle: FontStyles.loginLabel,
                                border: InputBorder.none,
                                suffixIcon: _errorIconEmail,
                              ),
                            ),
                          ),
                        ),
                        SizedBox(height: _screenHeight * 0.035,),//espaçamento entre os campos de email e senha
                        Villain(
                          villainAnimation: VillainAnimation.scale(
                            fromScale: 1.2,
                            toScale: 1.0,
                            from: Duration(milliseconds: 800),
                            to: Duration(milliseconds: 1000),
                          ),
                          secondaryVillainAnimation: VillainAnimation.fade(),
                          child: Container(//borda do campo de senha
                            padding: EdgeInsets.only(left: 15.0),
                            alignment: Alignment.center,
                            width: _screenWidth * 0.837,
                            height: _screenHeight * 0.09,
                            decoration: ShapeDecoration(
                              color: Colors.white,
                              shape: RoundedRectangleBorder(
                                  borderRadius: BorderRadius.circular(4.0),
                                  side: BorderSide(
                                      color: _actualPasswordBorderColor,
                                      style: BorderStyle.solid,
                                      width: 1.0
                                  )
                              ),
                            ),
                            child: TextField(//campo de senha
                              focusNode: _focusPasswordTextField,
                              style: FontStyles.loginLabel,
                              textCapitalization: TextCapitalization.none,
                              textInputAction: TextInputAction.done,
                              obscureText: true,
                              controller: _inputControllerPassword,
                              onChanged: (String val) {
                                if(!_firstEnter) {
                                  validatePassword();
                                }
                              },
                              onSubmitted: (val) {
                                SystemChannels.textInput.invokeMethod('TextInput.hide');
                                //_loginUser();
                              },
                              decoration: InputDecoration(
                                labelText: "Senha",
                                labelStyle: FontStyles.loginLabel,
                                border: InputBorder.none,
                                suffixIcon: _errorIconPassword
                              ),
                            ),
                          ),
                        ),
                        SizedBox(height: _screenHeight * 0.035,),//espaçamento entre o campo de senha e botão entrar
                        Villain(
                          villainAnimation: VillainAnimation.scale(
                            fromScale: 1.2,
                            toScale: 1.0,
                            from: Duration(milliseconds: 900),
                            to: Duration(milliseconds: 1100),
                          ),
                          secondaryVillainAnimation: VillainAnimation.fade(),
                          child: MaterialButton(//botão entrar
                            onPressed: () {
                              flushMessage.show(context);
                            },
                            minWidth: _screenWidth * 0.837,
                            height: _screenHeight * 0.09,
                            color: Color.fromARGB(255, 52, 92, 170),
                            textColor: Colors.white,
                            child: Text("entrar", style: FontStyles.loginButtonEnter,),
                          ),
                        ),
                        SizedBox(height: _screenHeight * 0.010,),
                        Villain(
                          villainAnimation: VillainAnimation.scale(
                            fromScale: 1.2,
                            toScale: 1.0,
                            from: Duration(milliseconds: 1000),
                            to: Duration(milliseconds: 1200),
                          ),
                          secondaryVillainAnimation: VillainAnimation.fade(),
                          child: FlatButton(
                            onPressed: () => print("esqueceu"),
                            child: Text("Esqueceu a senha?", style: FontStyles.loginForgetPassword,),
                          ),
                        )
                      ],
                    )
                  ],
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
  bool validateEmail() {
    Pattern pattern = r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$';
    RegExp regex = new RegExp(pattern);
    if (!regex.hasMatch(_inputControllerEmail.text)) {
      setState(() {
        _errorIconEmail = Icon(Icons.error, color: Colors.red,);
        _actualEmailBorderColor = _borderEmailFieldColorError;
      });
      return false;
    }else{
      setState(() {
        _errorIconEmail = null;
        _actualEmailBorderColor = _borderEmailFieldColor;
      });
      return true;
    }
  }
 bool validatePassword() {
    if (_inputControllerPassword.text.length < 1) {
      setState(() {
        _errorIconPassword = Icon(Icons.error, color: Colors.red,);
        _actualPasswordBorderColor = _borderPasswordFieldColorError;
      });
      return false;
    }else{
      setState(() {
        _errorIconPassword = null;
        _actualPasswordBorderColor = _borderPasswordFieldColor;
      });
      return true;
    }
  }
//  _loginUser() async {
//    bool emailValid = validateEmail();
//    bool passwordValid = validatePassword();
//
//    if(emailValid && passwordValid) {
//      dynamic response = await netUtil.post(
//          "http://192.168.1.192:3000/api/v3/customers/auth/sign_in",
//          headers: {
//            "Content-Type":"application/json"
//          },
//          body: {
//            "email": "[email protected]",
//            "password": "1020304050"
//          });
//      print(response.toString());
//    } else {
//      _firstEnter = false;
//      flushMessage.show(context);
//    }
//  }
  _animateOpenMainContainer() {
    setState(() {
      _marginVerticalMainContainer = 0.0;
      _marginHorizontalMainContainer = 0.0;
      _mainContainerBorderRadius = 0.0;
    });
  }
}

from flushbar.

AndreHaueisen avatar AndreHaueisen commented on September 3, 2024

@carnivash
Found the problem. It is an issue when you set isDismissible to false. Expect the fix today.
Thanks for the feedback.

from flushbar.

AndreHaueisen avatar AndreHaueisen commented on September 3, 2024

Version 0.8.3 released. Check if it solved your problems, please.

from flushbar.

AndreHaueisen avatar AndreHaueisen commented on September 3, 2024

Closing it for now. If the problem persists, please let me know.

from flushbar.

carnivash avatar carnivash commented on September 3, 2024

I am sorry, but just now i had time to test, it's working perfectly, thank you very much.

from flushbar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.