Created
July 5, 2024 10:48
-
-
Save rayliverified/ffccc3cfb423b9099471b064c75e52fd to your computer and use it in GitHub Desktop.
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
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return const MaterialApp( | |
title: 'MyApp Demo', | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Canvas2(), | |
), | |
); | |
} | |
} | |
class Canvas2 extends StatelessWidget { | |
const Canvas2({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
width: 327, | |
height: 525, | |
alignment: Alignment.center, | |
clipBehavior: Clip.hardEdge, | |
decoration: const BoxDecoration( | |
color: Colors.white, | |
), | |
child: SizedBox( | |
width: 229, | |
child: TextFormField( | |
keyboardType: TextInputType.text, | |
style: const TextStyle( | |
color: Colors.black, | |
fontSize: 14, | |
fontFamily: 'Roboto', | |
), | |
textAlign: TextAlign.left, | |
textAlignVertical: TextAlignVertical.center, | |
autocorrect: false, | |
minLines: null, | |
maxLength: 20, | |
autovalidateMode: AutovalidateMode.onUserInteraction, | |
validator: (value) { | |
if (value == null || value.isEmpty) { | |
return null; | |
} | |
final RegExp regex = RegExp(r'^[0-9]+$'); | |
final Match? match = regex.matchAsPrefix(value); | |
final bool isValid = | |
match?.start == 0 && match?.end == value.length; | |
if (isValid) return null; | |
return 'Only digits are allowed.'; | |
}, | |
cursorHeight: 14, | |
cursorRadius: const Radius.circular(2), | |
cursorColor: const Color(0xFF5C69E5), | |
decoration: InputDecoration( | |
labelText: 'Label', | |
labelStyle: const TextStyle( | |
color: Colors.grey, | |
fontSize: 14, | |
fontFamily: 'Roboto', | |
), | |
floatingLabelStyle: const TextStyle( | |
color: Colors.blue, | |
fontSize: 14, | |
fontFamily: 'Roboto', | |
), | |
hintText: 'Enter text', | |
hintStyle: const TextStyle( | |
color: Color(0xFF7F7F7F), | |
fontSize: 14, | |
fontFamily: 'Roboto', | |
), | |
hintMaxLines: 1, | |
errorStyle: const TextStyle( | |
color: Color(0xFFFF0000), | |
fontSize: 12, | |
fontFamily: 'Roboto', | |
), | |
errorMaxLines: 1, | |
floatingLabelBehavior: FloatingLabelBehavior.always, | |
isDense: true, | |
contentPadding: | |
const EdgeInsets.symmetric(horizontal: 12, vertical: 16), | |
counterText: '', | |
focusColor: Colors.blue, | |
hoverColor: const Color(0x197F7F7F), | |
errorBorder: OutlineInputBorder( | |
borderRadius: BorderRadius.circular(4.0), | |
borderSide: const BorderSide( | |
color: Color(0xFFFF0000), | |
), | |
), | |
focusedBorder: OutlineInputBorder( | |
borderRadius: BorderRadius.circular(4.0), | |
borderSide: const BorderSide( | |
color: Colors.blue, | |
width: 1.5, | |
), | |
), | |
focusedErrorBorder: OutlineInputBorder( | |
borderRadius: BorderRadius.circular(4.0), | |
borderSide: const BorderSide( | |
color: Color(0xFFFF0000), | |
), | |
), | |
disabledBorder: OutlineInputBorder( | |
borderRadius: BorderRadius.circular(4.0), | |
borderSide: const BorderSide( | |
color: Color(0x197F7F7F), | |
), | |
), | |
enabledBorder: OutlineInputBorder( | |
borderRadius: BorderRadius.circular(4.0), | |
borderSide: const BorderSide( | |
color: Color(0x809E9E9E), | |
width: 1.5, | |
), | |
), | |
border: OutlineInputBorder( | |
borderRadius: BorderRadius.circular(4.0), | |
borderSide: const BorderSide( | |
color: Color(0x809E9E9E), | |
width: 1.5, | |
), | |
), | |
alignLabelWithHint: true, | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment