Skip to content

Instantly share code, notes, and snippets.

@ctalladen78
Last active June 24, 2020 05:22
Show Gist options
  • Save ctalladen78/1a5cf346acdf08979574adabdd3d59db to your computer and use it in GitHub Desktop.
Save ctalladen78/1a5cf346acdf08979574adabdd3d59db to your computer and use it in GitHub Desktop.
Credit card style editor
// https://dartpad.dartlang.org/1a5cf346acdf08979574adabdd3d59db
import 'package:flutter/material.dart';
import 'dart:math';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: EditCardForm(),
);
}
}
class EditCardForm extends StatefulWidget {
EditCardForm({Key key}) : super(key: key);
_EditProfileFormState createState() => _EditProfileFormState();
}
class _EditProfileFormState extends State<EditCardForm> {
var _scaffoldKey = GlobalKey<ScaffoldState>();
var _formKey = GlobalKey<FormState>();
Color _avatarColor;
Icon _cardType;
var name = TextEditingController();
var bio = TextEditingController();
var bank = TextEditingController();
List<Color> colorsList = [CustomColors.olive, CustomColors.lime, CustomColors.midnightGreen, CustomColors.yellow, CustomColors.orange, CustomColors.pink, CustomColors.purple];
var _textStyle = TextStyle(color:Colors.white, fontWeight: FontWeight.bold);
void setAvatarImage(Color color) {
// var image = await ImagePicker.pickImage(source: ImageSource.camera);
setState(() {
_avatarColor = color;
});
}
void validateAnswers() {
if (name.value.text.isEmpty && bio.value.text.isEmpty){
_scaffoldKey.currentState.showSnackBar(const SnackBar(content: const Text('Please fill in all the blanks')));
} else {
_scaffoldKey.currentState.showSnackBar(const SnackBar(content: const Text('Successfully updated')));
_submitForm();
}
}
void _submitForm() {
setState(() {
});
}
Widget buildNameInput(BuildContext context, GlobalKey<FormState> key){
return TextFormField(
autofocus: true,
controller: name,
decoration: InputDecoration(
hintText: "Name",
contentPadding: EdgeInsets.symmetric(horizontal: 20.0),
// border: OutlineInputBorder(borderSide: BorderSide(width:2.0)),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0)
),
),
);
}
Widget buildMottoInput(BuildContext context, GlobalKey<FormState> key){
return SizedBox(
// width: MediaQuery.of(context).size.width - 70.0,
child: TextFormField(
maxLines: 1,
controller: bio,
decoration: InputDecoration(
hintText: "Share whats cool about yourself",
// hintStyle: TextStyle(fontStyle: ),
contentPadding: EdgeInsets.all( 15.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0)
),
),
)
);
}
List<Icon> iconlist =[Icon(Icons.terrain), Icon(Icons.sd_card), Icon(Icons.card_travel)].toList();
// terrain, sd_card, card_travel
Widget buildCardSelector(BuildContext context, GlobalKey<FormState> key){
return DropdownButton(
value: _cardType,
onChanged: (Icon newValue) {
setState(() {
_cardType = newValue;
});
},
items: iconlist.map((Icon item) =>
new DropdownMenuItem<Icon>(value: item, child: item)
)
.toList(),
);
}
Widget buildColorSelector(BuildContext context){
return Container(
height: 20,
alignment: Alignment.center,
width: 300,
// width: MediaQuery.of(context).size.width,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 7,
itemBuilder: (context, idx){
return GestureDetector(
onTap: (){
setAvatarImage(colorsList[idx]);
},
child: CircleAvatar(
radius: 20,
backgroundColor: colorsList[idx],
)
);
}
)
);
}
Widget buildUserAvatar(){
return Container(
height: 200,
width: MediaQuery.of(context).size.width - 50,
decoration: BoxDecoration(color: _avatarColor ?? Colors.grey
),
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.all(20),
child:
Row(children: <Widget>[
Icon(Icons.data_usage, color: Colors.blue,),
SizedBox(width: 20),
Text(bank.value.text, style: _textStyle),
]),
),
Padding(
padding: EdgeInsets.all(10),
child:
Text(bio.value.text, style: _textStyle),
),
Padding(
padding: EdgeInsets.all(20),
child:
Row(children: <Widget>[
Text(name.value.text, style: _textStyle,),
SizedBox(width: 20),
_cardType
],)
)
],
),
);
}
Widget buildHeader(BuildContext context){
return Center(
child: Container(
padding: EdgeInsets.all(20),
child:buildUserAvatar()
)
);
}
// title: Text("${user.firstName}", style: TextStyle(color: Colors.blueGrey, fontSize: 12.0, fontWeight: FontWeight.bold, fontFamily: "CircularStd-Book")),
Widget buildForm(){
return Form(
key: _formKey,
child: Column(children: <Widget>[
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.all(10.0),
child: Text("Card Name", style: TextStyle(color: CustomColors.ochreBlue, fontSize: 20.0, fontWeight: FontWeight.bold, fontFamily: "CircularStd-Book")),
),
// SizedBox(height: 5.0),
buildNameInput(context, _formKey),
SizedBox(height: 35.0),
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.all(10.0),
child: Text("Card Number",style: TextStyle(color: CustomColors.ochreBlue, fontSize: 20.0, fontWeight: FontWeight.bold, fontFamily: "CircularStd-Book")),
),
// SizedBox(height: 5.0),
buildMottoInput(context, _formKey),
SizedBox(height: 35.0),
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.all(10.0),
child: Text("Institute",style: TextStyle(color: CustomColors.ochreBlue, fontSize: 20.0, fontWeight: FontWeight.bold, fontFamily: "CircularStd-Book")),
),
buildCardSelector(context, _formKey)
],),
);
}
@override
void initState() {
bank.value = TextEditingValue(text: "AMEX Travel Direct");
bio.value = TextEditingValue(text: "8888 8888 8888 8888");
name.value = TextEditingValue(text: "John Appleseed");
_cardType = Icon(Icons.terrain);
_cardType = iconlist.first;
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(
centerTitle: true,
title:Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children:[
// Expanded(
// flex:2,
// child: Padding(padding:EdgeInsets.symmetric(horizontal:20.0),child:Text("Edit Profile", style: TextStyle(color: Colors.white,fontSize: 20.0, fontWeight: FontWeight.bold, fontFamily: "CircularStd-Book"),))
// ),
Expanded(
flex:1,
child: GestureDetector(
onTap: (){
validateAnswers();
},
child: Container(
// margin: EdgeInsets.only(left: 10.0, right: 10.0),
height: 35.0,
// width: 50,
padding: EdgeInsets.all(2.0),
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.cyan,
borderRadius: BorderRadius.circular(10.0),
),
child: Text("Save", style: TextStyle(color: CustomColors.orange, fontFamily: "CircularStd-Book",fontSize: 15.0),),
),
)
)
],
)
),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(horizontal: 10.0, vertical: 20.0),
child: buildColorSelector(context),
),
buildHeader(context),
Padding(
padding: EdgeInsets.symmetric(horizontal: 15.0, vertical: 20.0),
child: buildForm()
)
],)
),
);
}
}
class CustomColors {
static Color get darkTeal => Color.fromRGBO(46,97,112,1.0);
static Color get midnightGreen => Color.fromRGBO(89, 155, 158, 1.0);
static Color get purple => Color.fromRGBO(114,58,119, 1);
static Color get ochreBlue => Color.fromRGBO(35, 45, 75, 1.0);
static Color get orange => Color.fromRGBO(255,200,100, 1.0);
static Color get tealHighlight => Colors.tealAccent[700];
static Color get lime => Color.fromRGBO(205,246,80, 1.0); // 205,246,80
static Color get olive => Color.fromRGBO(154,160,57, 1.0); // 154,160,57
static Color get yellow => Colors.yellow; //
static Color get pink => Colors.pinkAccent[100]; //
Color getRandomColor(){
final random = Random();
return Color.fromRGBO(
random.nextInt(256),
random.nextInt(256),
random.nextInt(256),
1,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment