generated from GDGVIT/template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: password visibility + refactoring
- Loading branch information
1 parent
f5b1ff5
commit 44042c0
Showing
2 changed files
with
124 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class CustomTextField extends StatefulWidget { | ||
final String labelText; | ||
final bool obscureText; | ||
|
||
const CustomTextField({ | ||
super.key, | ||
required this.labelText, | ||
required this.obscureText, | ||
}); | ||
|
||
@override | ||
CustomTextFieldState createState() => CustomTextFieldState(); | ||
} | ||
|
||
class CustomTextFieldState extends State<CustomTextField> { | ||
bool _isPasswordVisible = false; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Text( | ||
widget.labelText, | ||
style: const TextStyle( | ||
color: Colors.white, | ||
fontSize: 18, | ||
fontFamily: 'Avenir Next', | ||
fontWeight: FontWeight.w600, | ||
), | ||
), | ||
const SizedBox(height: 10), | ||
Container( | ||
decoration: BoxDecoration( | ||
color: Colors.black.withOpacity(0.3), | ||
borderRadius: BorderRadius.circular(10), | ||
), | ||
child: TextField( | ||
style: const TextStyle(color: Colors.white), | ||
obscureText: widget.obscureText && !_isPasswordVisible, | ||
decoration: InputDecoration( | ||
border: OutlineInputBorder( | ||
borderRadius: BorderRadius.circular(10), | ||
), | ||
enabledBorder: OutlineInputBorder( | ||
borderRadius: BorderRadius.circular(10), | ||
borderSide: BorderSide( | ||
color: Colors.white.withOpacity(0.3), | ||
), | ||
), | ||
focusedBorder: OutlineInputBorder( | ||
borderRadius: BorderRadius.circular(10), | ||
borderSide: const BorderSide(color: Colors.white), | ||
), | ||
contentPadding: const EdgeInsets.symmetric(horizontal: 10), | ||
suffixIcon: widget.obscureText | ||
? IconButton( | ||
icon: Icon( | ||
_isPasswordVisible | ||
? Icons.visibility_outlined | ||
: Icons.visibility_off_outlined, | ||
color: Colors.white.withOpacity(0.3), | ||
), | ||
onPressed: () { | ||
setState(() { | ||
_isPasswordVisible = !_isPasswordVisible; | ||
}); | ||
}, | ||
) | ||
: null, | ||
), | ||
), | ||
), | ||
], | ||
); | ||
} | ||
} | ||
|
||
class LoginButton extends StatelessWidget { | ||
const LoginButton({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Container( | ||
width: double.infinity, | ||
height: 50, | ||
decoration: BoxDecoration( | ||
border: Border.all(color: Colors.white), | ||
borderRadius: BorderRadius.circular(25), | ||
), | ||
child: ElevatedButton( | ||
onPressed: () { | ||
// Handle login button press | ||
}, | ||
style: ElevatedButton.styleFrom( | ||
shadowColor: Colors.transparent, | ||
), | ||
child: const Text( | ||
'Login', | ||
style: TextStyle( | ||
color: Colors.white, | ||
fontSize: 18, | ||
fontFamily: 'Avenir Next', | ||
fontWeight: FontWeight.w600, | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |