skip to Main Content
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';


class SignIn extends StatefulWidget {
  const SignIn({Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() => _SignInState();
}

class _SignInState extends State<SignIn> {
  bool obscureTextPassword = true;

  @override
  Widget build(BuildContext context) => Card(child: Container(width: 300,child: Column(children: [_emailField(),_passwordField(),
            ],),),);}

Widget _emailField() => const Padding(
      padding: EdgeInsets.symmetric(vertical: 8, horizontal: 24),
      child: TextField(
        keyboardType: TextInputType.emailAddress,
        style: TextStyle(
          fontSize: 16,
          color: Colors.black,
        ),
        decoration: InputDecoration(
            border: InputBorder.none,
            hintText: 'Indirizzo Email',
            hintStyle: TextStyle(fontSize: 17),
            icon: Icon(
              FontAwesomeIcons.envelope,
              color: Colors.black,
              size: 22,
            )),
      ),
    );

Widget _passwordField() => Padding(
      padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 24),
      child: TextField(
        obscureText: obscureTextPassword,
        style: const TextStyle(
          fontSize: 16,
          color: Colors.black,
        ),
        decoration: InputDecoration(
          border: InputBorder.none,
          hintText: 'Password',
          hintStyle: const TextStyle(fontSize: 17),
          icon: const Icon(
            FontAwesomeIcons.lock,
            color: Colors.black,
            size: 22,
          ),
          suffixIcon: GestureDetector(
              onTap: () {
                setState(() {
                  obscureTextPassword = !obscureTextPassword;
                });
              },
              child: Icon(
                  obscureTextPassword
                      ? FontAwesomeIcons.eye
                      : FontAwesomeIcons.eyeSlash,
                  size: 15,
                  color: Colors.black)),
        ),
      ),
    );

2

Answers


  1. Add the variable both to your state class (_SignInState) and your widget class (SignIn). Assign them in both constructors. Then pass the variable from the widget class to the state class in Widget.createState. You can then access the variable in the build method.

    Login or Signup to reply.
  2. It would be great if you could mention more details. But I’ll provide you with an example let me know if it resolves the issue you are facing:

    
    class MyWidget extends StatelessWidget {
      final int value;
    
      // Approach 1: Using Positional argument
      // Use this like MyWidget(10);
      const MyWidget(this.value); // <- Use this
    
      // Approach 2: Using the named argument
      // Use this like MyWidget(value: 10);
      const MyWidget({required this.value}); // <- Or use this
    
      @override
      Widget build(BuildContext context) {
        return Container();
      }
    }
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search