본문 바로가기
프로그래밍/Flutter-Dart

[Flutter] Login App (2)

by 채연2 2021. 3. 24.

 

 

https://cording-cossk3.tistory.com/106

 

[Flutter] Login App (1)

main.dart import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'settings.dart'; import 'login.dart'; import 'package:fluttertoast/fluttertoast.dart'; void main() => runApp(MyApp()); class MyApp extends StatefulWidget { @o

cording-cossk3.tistory.com


이전에 만들었던 login app에서 비밀번호 visible 이벤트를 주려고 한다.

 

StatelessWidget ▶ StatefulWidget 변경

class Login extends StatefulWidget { 
   const Login(this.onSubmit);
   final VoidCallback onSubmit;

   @override
   LoginState createState() => LoginState(onSubmit);
}

class LoginState extends State<Login> {
   ...
}

 

 

 

TextField icon 추가 및 이벤트 주기

bool _isobscure = true;

@override
void initState() {
   _isobscure = true;
}

TextField(
   controller: _pass,
   decoration: InputDecoration(
      hintText: 'Enter a password',
      suffixIcon: IconButton(
         icon: Icon(
            Icons.remove_red_eye,
            color: _isobscure ? Colors.grey : Colors.black,
         ),
         onPressed: () {
            setState(() {
               _isobscure = !_isobscure;
            });
         },
      )
   ),
   obscureText: _isobscure,
)

 

 

 

결과

 

 

 

320x100

댓글