Skip to content

Instantly share code, notes, and snippets.

@mtellect
Last active May 12, 2018 12:15
Show Gist options
  • Save mtellect/e96482e557efa3de743586e15e8b16ab to your computer and use it in GitHub Desktop.
Save mtellect/e96482e557efa3de743586e15e8b16ab to your computer and use it in GitHub Desktop.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class InputField extends StatelessWidget {
final IconData icon;
final String hintText;
final TextInputType textInputType;
final Color textFieldColor, iconColor;
final bool obscureText;
final double bottomMargin;
final double topMargin;
final double rightMargin;
final double leftMargin;
final TextStyle textStyle, hintStyle;
var validateFunction;
var onSaved;
Key key;
final TextEditingController controller;
//passing props in the Constructor.
//Java like style
InputField(
{this.key,
this.hintText,
this.obscureText,
this.textInputType,
this.textFieldColor,
this.icon,
this.iconColor,
this.bottomMargin,
this.topMargin,
this.rightMargin,
this.leftMargin,
this.textStyle,
this.validateFunction,
this.onSaved,
this.hintStyle,
this.controller});
@override
Widget build(BuildContext context) {
// TODO: implement build
return (new Container(
padding: EdgeInsets.only(),
margin: new EdgeInsets.only(
bottom: bottomMargin,
right: rightMargin,
top: topMargin,
left: leftMargin),
child: new DecoratedBox(
decoration: new BoxDecoration(
borderRadius: new BorderRadius.all(new Radius.circular(5.0)),
color: iconColor.withAlpha(50)),
child: new Container(
margin: EdgeInsets.only(left: 10.0),
child: new TextFormField(
controller: controller,
style: textStyle,
key: key,
obscureText: obscureText,
keyboardType: textInputType,
validator: validateFunction,
onSaved: onSaved,
decoration: new InputDecoration(
border: InputBorder.none,
hintText: hintText,
hintStyle: hintStyle,
suffixIcon: new Padding(
padding: const EdgeInsets.all(8.0),
// child: new Icon(
// icon,
// color: iconColor,
// ),
child: new CupertinoButton(
padding: EdgeInsets.zero,
child: const Icon(
CupertinoIcons.search,
color: Colors.pink,
semanticLabel: 'Search',
),
onPressed: () {
//Navigator.pushNamed(context, Base.favoriteScreen);
},
),
),
),
),
),
)));
}
}
new InputField(
controller: searchTxtController,
hintText: "Search for cakes and fast foods",
//hintStyle: new TextStyle(color: Colors.pink),
obscureText: false,
textInputType: TextInputType.text,
textStyle: new TextStyle(color: Colors.pink),
textFieldColor: Colors.pink,
iconColor: Colors.pink,
icon: Icons.search,
bottomMargin: 10.0,
rightMargin: 10.0,
topMargin: 10.0,
leftMargin: 10.0,
onSaved: (String name) {},
),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment