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

Error when trying to show flushbar #6

Closed
carnivash opened this issue Sep 5, 2018 · 10 comments
Closed

Error when trying to show flushbar #6

carnivash opened this issue Sep 5, 2018 · 10 comments
Labels
bug Something isn't working

Comments

@carnivash
Copy link

Wherever i call show(context) for flushbar i get a bunch of errors:

flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following assertion was thrown building _FocusScopeMarker(dirty):
flutter: A build function returned null.
flutter: The offending widget is: _FocusScopeMarker
flutter: Build functions must never return null. To return an empty space that causes the building widget to
flutter: fill available room, return "new Container()". To return an empty space that takes as little room as
flutter: possible, return "new Container(width: 0.0, height: 0.0)".
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0 debugWidgetBuilderValue. (package:flutter/src/widgets/debug.dart:250:7)
flutter: #1 debugWidgetBuilderValue (package:flutter/src/widgets/debug.dart:259:4)
flutter: #2 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3656:7)
flutter: #3 Element.rebuild (package:flutter/src/widgets/framework.dart:3508:5)
flutter: #4 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3635:5)
flutter: #5 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3630:5)
flutter: #6 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #7 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #8 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4667:14)
flutter: #9 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #10 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #11 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3666:16)
flutter: #12 Element.rebuild (package:flutter/src/widgets/framework.dart:3508:5)
flutter: #13 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3635:5)
flutter: #14 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3782:11)
flutter: #15 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3630:5)
flutter: #16 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #17 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #18 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4667:14)
flutter: #19 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #20 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #21 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4667:14)
flutter: #22 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #23 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #24 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4667:14)
flutter: #25 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #26 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #27 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3666:16)
flutter: #28 Element.rebuild (package:flutter/src/widgets/framework.dart:3508:5)
flutter: #29 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3635:5)
flutter: #30 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3630:5)
flutter: #31 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #32 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #33 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4667:14)
flutter: #34 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #35 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #36 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3666:16)
flutter: #37 Element.rebuild (package:flutter/src/widgets/framework.dart:3508:5)
flutter: #38 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3635:5)
flutter: #39 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3630:5)
flutter: #40 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #41 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #42 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3666:16)
flutter: #43 Element.rebuild (package:flutter/src/widgets/framework.dart:3508:5)
flutter: #44 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3635:5)
flutter: #45 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3630:5)
flutter: #46 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #47 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #48 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3666:16)
flutter: #49 Element.rebuild (package:flutter/src/widgets/framework.dart:3508:5)
flutter: #50 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3635:5)
flutter: #51 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3782:11)
flutter: #52 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3630:5)
flutter: #53 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #54 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #55 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4667:14)
flutter: #56 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #57 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #58 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3666:16)
flutter: #59 Element.rebuild (package:flutter/src/widgets/framework.dart:3508:5)
flutter: #60 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3635:5)
flutter: #61 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3630:5)
flutter: #62 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #63 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #64 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4667:14)
flutter: #65 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #66 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #67 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3666:16)
flutter: #68 Element.rebuild (package:flutter/src/widgets/framework.dart:3508:5)
flutter: #69 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3635:5)
flutter: #70 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3782:11)
flutter: #71 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3630:5)
flutter: #72 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #73 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #74 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3666:16)
flutter: #75 Element.rebuild (package:flutter/src/widgets/framework.dart:3508:5)
flutter: #76 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3635:5)
flutter: #77 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3782:11)
flutter: #78 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3630:5)
flutter: #79 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #80 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #81 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4667:14)
flutter: #82 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #83 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #84 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3666:16)
flutter: #85 Element.rebuild (package:flutter/src/widgets/framework.dart:3508:5)
flutter: #86 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3635:5)
flutter: #87 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3782:11)
flutter: #88 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3630:5)
flutter: #89 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #90 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #91 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4667:14)
flutter: #92 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #93 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #94 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3666:16)
flutter: #95 Element.rebuild (package:flutter/src/widgets/framework.dart:3508:5)
flutter: #96 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3635:5)
flutter: #97 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3782:11)
flutter: #98 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3630:5)
flutter: #99 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #100 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #101 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3666:16)
flutter: #102 Element.rebuild (package:flutter/src/widgets/framework.dart:3508:5)
flutter: #103 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3635:5)
flutter: #104 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3630:5)
flutter: #105 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #106 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #107 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4667:14)
flutter: #108 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #109 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #110 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3666:16)
flutter: #111 Element.rebuild (package:flutter/src/widgets/framework.dart:3508:5)
flutter: #112 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3635:5)
flutter: #113 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3630:5)
flutter: #114 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #115 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #116 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3666:16)
flutter: #117 Element.rebuild (package:flutter/src/widgets/framework.dart:3508:5)
flutter: #118 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3635:5)
flutter: #119 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3630:5)
flutter: #120 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #121 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #122 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3666:16)
flutter: #123 Element.rebuild (package:flutter/src/widgets/framework.dart:3508:5)
flutter: #124 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3635:5)
flutter: #125 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3630:5)
flutter: #126 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #127 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #128 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3666:16)
flutter: #129 Element.rebuild (package:flutter/src/widgets/framework.dart:3508:5)
flutter: #130 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3635:5)
flutter: #131 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3782:11)
flutter: #132 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3630:5)
flutter: #133 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2920:14)
flutter: #134 Element.updateChild (package:flutter/src/widgets/framework.dart:2723:12)
flutter: #135 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4450:32)
flutter: #136 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4782:17)
flutter: #137 Element.updateChild (package:flutter/src/widgets/framework.dart:2712:15)
flutter: #138 _TheatreElement.update (package:flutter/src/widgets/overlay.dart:507:16)
flutter: #139 Element.updateChild (package:flutter/src/widgets/framework.dart:2712:15)
flutter: #140 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3666:16)
flutter: #141 Element.rebuild (package:flutter/src/widgets/framework.dart:3508:5)
flutter: #142 StatefulElement.update (package:flutter/src/widgets/framework.dart:3812:5)
flutter: #143 Element.updateChild (package:flutter/src/widgets/framework.dart:2712:15)
flutter: #144 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3666:16)
flutter: #145 Element.rebuild (package:flutter/src/widgets/framework.dart:3508:5)
flutter: #146 ProxyElement.update (package:flutter/src/widgets/framework.dart:3922:5)
flutter: #147 Element.updateChild (package:flutter/src/widgets/framework.dart:2712:15)
flutter: #148 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4674:14)
flutter: #149 Element.updateChild (package:flutter/src/widgets/framework.dart:2712:15)
flutter: #150 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3666:16)
flutter: #151 Element.rebuild (package:flutter/src/widgets/framework.dart:3508:5)
flutter: #152 StatefulElement.update (package:flutter/src/widgets/framework.dart:3812:5)
flutter: #153 Element.updateChild (package:flutter/src/widgets/framework.dart:2712:15)
flutter: #154 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4674:14)
flutter: #155 Element.updateChild (package:flutter/src/widgets/framework.dart:2712:15)
flutter: #156 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4674:14)
flutter: #157 Element.updateChild (package:flutter/src/widgets/framework.dart:2712:15)
flutter: #158 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3666:16)
flutter: #159 Element.rebuild (package:flutter/src/widgets/framework.dart:3508:5)
flutter: #160 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2255:33)
flutter: #161 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:653:20)
flutter: #162 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:214:5)
flutter: #163 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
flutter: #164 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
flutter: #165 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
flutter: #166 _invoke (dart:ui/hooks.dart:128:13)
flutter: #167 _drawFrame (dart:ui/hooks.dart:117:3)
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.
flutter: Another exception was thrown: A build function returned null.

@AndreHaueisen
Copy link
Owner

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.

@carnivash
Copy link
Author

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,),
),

@AndreHaueisen
Copy link
Owner

AndreHaueisen commented Sep 5, 2018

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,),
),

@carnivash
Copy link
Author

I tried that, same error.

@AndreHaueisen
Copy link
Owner

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

@carnivash
Copy link
Author

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": "chrystal@altenwerth.co.uk",
//            "password": "1020304050"
//          });
//      print(response.toString());
//    } else {
//      _firstEnter = false;
//      flushMessage.show(context);
//    }
//  }
  _animateOpenMainContainer() {
    setState(() {
      _marginVerticalMainContainer = 0.0;
      _marginHorizontalMainContainer = 0.0;
      _mainContainerBorderRadius = 0.0;
    });
  }
}

@AndreHaueisen AndreHaueisen added the bug Something isn't working label Sep 7, 2018
@AndreHaueisen
Copy link
Owner

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

@AndreHaueisen
Copy link
Owner

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

@AndreHaueisen
Copy link
Owner

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

@carnivash
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants