From a4160498e1dd5dfbb14713287a2053422f8deaa7 Mon Sep 17 00:00:00 2001 From: saritabirare Date: Mon, 16 Sep 2024 17:22:40 +0530 Subject: [PATCH] 1)Common widget added --- lib/widgets/comman_background.dart | 27 +++++++ lib/widgets/comman_text_from_filed.dart | 93 +++++++++++++++++++++++++ lib/widgets/common_appbar.dart | 29 ++++++++ lib/widgets/common_elevated_button.dart | 46 ++++++++++++ 4 files changed, 195 insertions(+) create mode 100644 lib/widgets/comman_background.dart create mode 100644 lib/widgets/comman_text_from_filed.dart create mode 100644 lib/widgets/common_appbar.dart create mode 100644 lib/widgets/common_elevated_button.dart diff --git a/lib/widgets/comman_background.dart b/lib/widgets/comman_background.dart new file mode 100644 index 0000000..0a8d621 --- /dev/null +++ b/lib/widgets/comman_background.dart @@ -0,0 +1,27 @@ +import 'package:flutter/material.dart'; + +class CommonBackground extends StatelessWidget { + final Widget child; + final bool isFullWidth; + + const CommonBackground( + {super.key, required this.child, this.isFullWidth = true, appBar}); + + @override + Widget build(BuildContext context) { + return Container( + color: Colors.white, + child: Stack(children: [ + Container( + height: isFullWidth + ? MediaQuery.sizeOf(context).height + : MediaQuery.sizeOf(context).height * 0.90, + decoration: BoxDecoration( + image: const DecorationImage( + image: AssetImage('assets/images/image_1.png'), + fit: BoxFit.cover))), + child + ]), + ); + } +} diff --git a/lib/widgets/comman_text_from_filed.dart b/lib/widgets/comman_text_from_filed.dart new file mode 100644 index 0000000..e255012 --- /dev/null +++ b/lib/widgets/comman_text_from_filed.dart @@ -0,0 +1,93 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +class CommonTextFormField extends StatefulWidget { + final String title; + final String? label; + final TextEditingController? controller; + //final TextCapitalization textCapitalization; + final String? Function(String?)? validator; + final Color? fillColor; + final bool? readOnly; + final int? maxLines; + final double? height; + final TextInputType? keyboardType; + final List? inputFormatters; + final int? maxLength; + final bool obscureText; + final void Function(String)? onChanged; + + const CommonTextFormField({ + super.key, + required this.title, + this.label, + this.controller, + this.validator, + this.fillColor, + this.readOnly, + this.maxLines, + this.height, + this.keyboardType, + this.inputFormatters, + this.maxLength, + this.onChanged, + // this.textCapitalization = TextCapitalization.sentences, + this.obscureText = false, + }); + + @override + _CommonTextFormFieldState createState() => _CommonTextFormFieldState(); +} + +class _CommonTextFormFieldState extends State { + bool _isObscured = true; + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + TextFormField( + controller: widget.controller, + //textCapitalization: widget.textCapitalization, + readOnly: widget.readOnly ?? false, + maxLines: widget.maxLines ?? 1, + maxLength: widget.maxLength, + onChanged: widget.onChanged, + onTapOutside: (event) => FocusScope.of(context).unfocus(), + validator: widget.validator, + keyboardType: widget.keyboardType, + inputFormatters: widget.inputFormatters, + obscureText: widget.obscureText && _isObscured, + decoration: InputDecoration( + hintText: widget.title, + labelText: widget.label, + contentPadding: const EdgeInsets.only(bottom: 10, left: 10), + filled: true, + suffixIcon: widget.obscureText + ? IconButton( + icon: Icon( + _isObscured ? Icons.visibility : Icons.visibility_off, + color: Colors.grey, + ), + onPressed: () { + setState(() { + _isObscured = !_isObscured; + }); + }, + ) + : null, + focusedBorder: const OutlineInputBorder( + borderRadius: BorderRadius.all(Radius.circular(6)), + borderSide: BorderSide(color: Colors.transparent), + ), + enabledBorder: const OutlineInputBorder( + borderRadius: BorderRadius.all(Radius.circular(6)), + borderSide: BorderSide(color: Colors.transparent), + ), + fillColor: widget.fillColor ?? Colors.white, + ), + ), + ], + ); + } +} diff --git a/lib/widgets/common_appbar.dart b/lib/widgets/common_appbar.dart new file mode 100644 index 0000000..af77655 --- /dev/null +++ b/lib/widgets/common_appbar.dart @@ -0,0 +1,29 @@ +import 'package:flutter/material.dart'; + +class CommonAppBar extends StatelessWidget implements PreferredSizeWidget { + final Widget title; + final List? actions; + final TabBar? bottom; + + const CommonAppBar({super.key, required this.title, this.actions, required Color backgroundColor, required int elevation, this.bottom}); + + @override + Widget build(BuildContext context) { + return AppBar( + centerTitle: true, + leading: Builder(builder: (context) { + return IconButton( + onPressed: () => Scaffold.of(context).openDrawer(), + icon: const Icon(Icons.menu), + color: Colors.white); + }), + backgroundColor: Colors.transparent, + bottom: bottom, + title: title, + toolbarHeight: kToolbarHeight+20, + actions: actions); + } + + @override + Size get preferredSize => const Size.fromHeight(kToolbarHeight); +} diff --git a/lib/widgets/common_elevated_button.dart b/lib/widgets/common_elevated_button.dart new file mode 100644 index 0000000..d8777b0 --- /dev/null +++ b/lib/widgets/common_elevated_button.dart @@ -0,0 +1,46 @@ +import 'package:flutter/material.dart'; + +class CommonElevatedButton extends StatelessWidget { + final String text; + final void Function()? onPressed; + final double? height; + final double? width; + final double? borderRadius; + final Color? backgroundColor; + final bool isLoading; + + const CommonElevatedButton( + {super.key, + required this.text, + this.onPressed, + this.borderRadius, + this.backgroundColor, + this.height, + this.width, + this.isLoading = false}); + + @override + Widget build(BuildContext context) { + return SizedBox( + height: height ?? kToolbarHeight - 25, + width: width ?? 200, + child: ElevatedButton( + onPressed: isLoading ? null : onPressed, + style: ElevatedButton.styleFrom( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(borderRadius ?? 6)), + backgroundColor: backgroundColor ?? const Color(0xff1E1E1E), + side: const BorderSide(color: Colors.transparent)), + child: Center( + child: isLoading + ? const CircularProgressIndicator( + backgroundColor: Colors.white, + valueColor: AlwaysStoppedAnimation(Colors.black)) + : Text(text, + style: const TextStyle( + fontSize: 15, + color: Colors.white, + fontWeight: FontWeight.w400, + fontFamily: 'Anek'))))); + } +}