TextField wrapped in a Transform.translate does not focus when clicked

Viewed 401

This has been very confusing to me since the TextField wrapped in a SizedBox only, works perfectly; but it appears to be a simple image (it can't be tapped, nor focused) when I wrap that same piece of code in a Transform.translate widget. Also, if I change the Transform.translate to a Positioned widget, the TextField works perfectly, but I'd like to understand why this is happening, because I am required to use Transform.translate over Positioned for this special project.

class Login extends StatelessWidget {
  Login({
    Key key,
  }) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xfff4f6fa),
      body: Stack(
        children: <Widget>[   
             SizedBox(
              width: 302.0,
              height: 60.0,
              child: TextField(
             decoration: InputDecoration(
               hintText: 'Correo electrónico *',
               prefixIcon: Icon(Icons.send),
               border: OutlineInputBorder(
                 borderSide:
                     BorderSide(width: 1.0, color: const Color(0xffe7e7e7)),
                 borderRadius: BorderRadius.circular(4.0),
               ),
             ),
             style: TextStyle(
               fontFamily: 'Nunito',
               fontSize: 14,
               color: const Color(0xff777777),
               height: 1.4285714285714286,
             ),
             textAlign: TextAlign.left,
             onChanged: (String value) async {
               
             },
             onSubmitted: (String value) async {
               
             },
              ),
            ),
          // Positioned(
          Transform.translate(
            offset: Offset(36.0, 317.8),
            // left: 36,
            // top: 317.8,
            child:
                // Adobe XD layer: 'input:mail' (component)
                SizedBox(
              width: 302.0,
              height: 60.0,
              
              child: TextField(
                decoration: InputDecoration(
                  hintText: 'Correo electrónico *',
                  prefixIcon: Icon(Icons.send),
                  border: OutlineInputBorder(
                    borderSide:
                        BorderSide(width: 1.0, color: const Color(0xffe7e7e7)),
                    borderRadius: BorderRadius.circular(4.0),
                  ),
                ),
                style: TextStyle(
                  fontFamily: 'Nunito',
                  fontSize: 14,
                  color: const Color(0xff777777),
                  height: 1.4285714285714286,
                ),
                textAlign: TextAlign.left,
                onChanged: (String value) async {
                  
                },
                onSubmitted: (String value) async {
                  
                },
              ),
            ),
          ),
          
        ],
      ),
    );
  }
}

As mentioned before, both inputs show on the screen (one at the center and one at the top) only the TextField wrapped with a SizeBox (first element of the Stack, at the top of the sreen)can be tapped, nothing happens when the one at the center of the screen (second element of the stack, located there because of the translation) is tapped.

1 Answers

Try debugging and see the layout grid lines and correct boundaries of widget using Flutter inspector. That should give you a better idea at why is it behaving this way. Seems like when You use the Transform widget, it doesnt register the hit as it merely moves the boundaries and not the tap area. Try wrapping the Transform widget with a GestureDetector and see. You can also follow a similar issue on GitHub: https://github.com/flutter/flutter/issues/27587

Related