You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			143 lines
		
	
	
		
			4.7 KiB
		
	
	
	
		
			Dart
		
	
			
		
		
	
	
			143 lines
		
	
	
		
			4.7 KiB
		
	
	
	
		
			Dart
		
	
import 'package:flutter/material.dart';
 | 
						|
import 'package:mohem_flutter_app/classes/colors.dart';
 | 
						|
import 'package:mohem_flutter_app/extensions/int_extensions.dart';
 | 
						|
import 'package:mohem_flutter_app/extensions/widget_extensions.dart';
 | 
						|
 | 
						|
class InputWidget extends StatefulWidget {
 | 
						|
  final String labelText;
 | 
						|
  final String hintText;
 | 
						|
  final TextEditingController controller;
 | 
						|
  final VoidCallback? suffixTap;
 | 
						|
  final bool isEnable;
 | 
						|
  final bool hasSelection;
 | 
						|
  final int? lines;
 | 
						|
  final bool isInputTypeNum;
 | 
						|
  final bool isTextIsPassword;
 | 
						|
  final bool isBackgroundEnable;
 | 
						|
  final bool isEnableBorder;
 | 
						|
  final double verticalPadding;
 | 
						|
  final double horizontalPadding;
 | 
						|
  final Function(String)? onChange;
 | 
						|
 | 
						|
  InputWidget(
 | 
						|
    this.labelText,
 | 
						|
    this.hintText,
 | 
						|
    this.controller, {
 | 
						|
    Key? key,
 | 
						|
    this.isTextIsPassword = false,
 | 
						|
    this.suffixTap,
 | 
						|
    this.isEnable = true,
 | 
						|
    this.hasSelection = false,
 | 
						|
    this.isEnableBorder = true,
 | 
						|
    this.lines = 1,
 | 
						|
    this.onChange,
 | 
						|
    this.isInputTypeNum = false,
 | 
						|
    this.isBackgroundEnable = false,
 | 
						|
    this.verticalPadding = 15,
 | 
						|
    this.horizontalPadding = 16,
 | 
						|
  }) : super(key: key);
 | 
						|
 | 
						|
  @override
 | 
						|
  _InputWidgetState createState() {
 | 
						|
    return _InputWidgetState();
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
class _InputWidgetState extends State<InputWidget> {
 | 
						|
  late bool isObscureText;
 | 
						|
 | 
						|
  @override
 | 
						|
  void initState() {
 | 
						|
    super.initState();
 | 
						|
    isObscureText = widget.isTextIsPassword;
 | 
						|
  }
 | 
						|
 | 
						|
  @override
 | 
						|
  void dispose() {
 | 
						|
    super.dispose();
 | 
						|
  }
 | 
						|
 | 
						|
  @override
 | 
						|
  Widget build(BuildContext context) {
 | 
						|
    return Container(
 | 
						|
      padding: EdgeInsets.only(left: widget.horizontalPadding, right: widget.horizontalPadding, bottom: widget.verticalPadding, top: widget.verticalPadding),
 | 
						|
      alignment: Alignment.center,
 | 
						|
      decoration: BoxDecoration(
 | 
						|
        borderRadius: BorderRadius.circular(15),
 | 
						|
        color: widget.isBackgroundEnable ? Color(0xffF7F7F7) : Colors.white,
 | 
						|
        border: Border.all(
 | 
						|
          color: widget.isEnableBorder ? Color(0xffefefef) : Colors.transparent,
 | 
						|
          width: 1,
 | 
						|
        ),
 | 
						|
      ),
 | 
						|
      child: InkWell(
 | 
						|
        onTap: widget.hasSelection ? () {} : null,
 | 
						|
        child: Row(
 | 
						|
          children: [
 | 
						|
            Expanded(
 | 
						|
              child: Column(
 | 
						|
                mainAxisSize: MainAxisSize.min,
 | 
						|
                crossAxisAlignment: CrossAxisAlignment.start,
 | 
						|
                children: [
 | 
						|
                  Text(
 | 
						|
                    widget.labelText,
 | 
						|
                    style: const TextStyle(
 | 
						|
                      fontSize: 11,
 | 
						|
                      fontWeight: FontWeight.w600,
 | 
						|
                      color: Color(0xff2B353E),
 | 
						|
                      letterSpacing: -0.44,
 | 
						|
                    ),
 | 
						|
                  ),
 | 
						|
                  TextField(
 | 
						|
                    enabled: widget.isEnable,
 | 
						|
                    scrollPadding: EdgeInsets.zero,
 | 
						|
                    keyboardType: widget.isInputTypeNum ? TextInputType.number : TextInputType.text,
 | 
						|
                    controller: widget.controller,
 | 
						|
                    maxLines: widget.lines,
 | 
						|
                    obscuringCharacter: "*",
 | 
						|
                    obscureText: isObscureText,
 | 
						|
                    onChanged: widget.onChange,
 | 
						|
                    style: const TextStyle(
 | 
						|
                      fontSize: 14,
 | 
						|
                      height: 21 / 14,
 | 
						|
                      fontWeight: FontWeight.w400,
 | 
						|
                      color: Color(0xff2B353E),
 | 
						|
                      letterSpacing: -0.44,
 | 
						|
                    ),
 | 
						|
                    decoration: InputDecoration(
 | 
						|
                      isDense: true,
 | 
						|
                      hintText: widget.hintText,
 | 
						|
                      hintStyle: const TextStyle(
 | 
						|
                        fontSize: 14,
 | 
						|
                        height: 21 / 14,
 | 
						|
                        fontWeight: FontWeight.w400,
 | 
						|
                        color: Color(0xff575757),
 | 
						|
                        letterSpacing: -0.56,
 | 
						|
                      ),
 | 
						|
                      suffixIconConstraints: const BoxConstraints(minWidth: 50),
 | 
						|
                      suffixIcon: widget.suffixTap == null ? null : IconButton(icon: const Icon(Icons.mic, color: MyColors.darkTextColor), onPressed: widget.suffixTap),
 | 
						|
                      contentPadding: EdgeInsets.zero,
 | 
						|
                      border: InputBorder.none,
 | 
						|
                      focusedBorder: InputBorder.none,
 | 
						|
                      enabledBorder: InputBorder.none,
 | 
						|
                    ),
 | 
						|
                  ),
 | 
						|
                ],
 | 
						|
              ),
 | 
						|
            ),
 | 
						|
            if (widget.isTextIsPassword) ...[
 | 
						|
              16.width,
 | 
						|
              Icon(isObscureText ? Icons.visibility_rounded : Icons.visibility_off_rounded).onPress(() {
 | 
						|
                setState(() {
 | 
						|
                  isObscureText = !isObscureText;
 | 
						|
                });
 | 
						|
              })
 | 
						|
            ],
 | 
						|
            if (widget.hasSelection) Icon(Icons.keyboard_arrow_down_outlined),
 | 
						|
          ],
 | 
						|
        ),
 | 
						|
      ),
 | 
						|
    );
 | 
						|
  }
 | 
						|
}
 |