Skip to content

Commit

Permalink
added svg in list item,
Browse files Browse the repository at this point in the history
sqflite crud modification
  • Loading branch information
Nidhi Pandya committed Oct 1, 2019
1 parent 8be53d6 commit d4e0613
Show file tree
Hide file tree
Showing 11 changed files with 276 additions and 116 deletions.
54 changes: 54 additions & 0 deletions assets/europeanunion.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
177 changes: 91 additions & 86 deletions lib/database/add_user_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,126 +15,131 @@ class AddUserDialog {

final etFirstname = TextEditingController();
final etLastname = TextEditingController();
final etDob = TextEditingController();
final etAddress = TextEditingController();
User user;

Widget buildAboutDialog(BuildContext context, _myHomePageState, bool isEdit,
User user) {
/*final FocusNode _firstNameFocus = FocusNode();
final FocusNode _lastNameFocus = FocusNode();
final FocusNode _dobFocus = FocusNode();*/

String _firstName, _lastName, _dob;
Widget buildAboutDialog(
BuildContext context, _myHomePageState, bool isEdit, User user) {
String _firstName, _lastName, _address;

if (user != null) {
this.user = user;
etFirstname.text = user.firstName;
etLastname.text = user.lastName;
etDob.text = user.dob;
etAddress.text = user.address;
}

final GlobalKey<FormState> _addUserKey = GlobalKey<FormState>();

return AlertDialog(
title: Text(isEdit ? 'Edit' : 'Add new User'),
title: Text(isEdit ? 'Update User' : 'Add User'),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
// it will work as a gravity.
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
TextFormField(
decoration: InputDecoration(labelText: "FirstName"),
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
controller: etFirstname,
/* focusNode: _firstNameFocus,
mainAxisSize: MainAxisSize.min,
// it will work as a gravity.
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
TextFormField(
decoration: InputDecoration(labelText: "FirstName"),
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
controller: etFirstname,
/* focusNode: _firstNameFocus,
onFieldSubmitted: (term) {
_fieldFocusChange(context, _firstNameFocus, _lastNameFocus);
},*/

//textDirection: TextDirection.rtl,
validator: (name) {
if (name.isEmpty) {
return 'Please enter firstname';
}
return null;
},
onSaved: (String firstName) {
_firstName = firstName;
}),
TextFormField(
decoration: InputDecoration(labelText: "LastName "),
keyboardType: TextInputType.text,
//focusNode: _lastNameFocus,
controller: etLastname,
autofocus: false,
textInputAction: TextInputAction.next,

//for hiding the 1/10 lable from the form field.
buildCounter: (BuildContext context,
//textDirection: TextDirection.rtl,
validator: (name) {
if (name.isEmpty) {
return 'Please enter firstname';
}
return null;
},
onSaved: (String firstName) {
_firstName = firstName;
}),
TextFormField(
decoration: InputDecoration(labelText: "LastName "),
keyboardType: TextInputType.text,
//focusNode: _lastNameFocus,
controller: etLastname,
autofocus: false,
textInputAction: TextInputAction.next,

//for hiding the 1/10 lable from the form field.
buildCounter: (BuildContext context,
{int currentLength, int maxLength, bool isFocused}) =>
null,
/* onFieldSubmitted: (term) {
_fieldFocusChange(context, _lastNameFocus, _dobFocus);
},*/
validator: (lastName) {
if (lastName.isEmpty) {
return 'Please enter lastname ';
}
return null;
},
onSaved: (String lastName) {
_lastName = lastName;
}

/*validator: (number) {
validator: (lastName) {
if (lastName.isEmpty) {
return 'Please enter lastname ';
}
return null;
},
onSaved: (String lastName) {
_lastName = lastName;
}

/*validator: (number) {
if (number.isEmpty) {
return 'Please enter Number';
}
return null;
},*/
),
TextFormField(
decoration: InputDecoration(labelText: "DD-MM-YYYY"),
keyboardType: TextInputType.text,
// focusNode: _dobFocus,
autofocus: false,
controller: etDob,
textInputAction: TextInputAction.done,
validator: (address) {
if (address.isEmpty) {
return 'Please enter dob';
}
return null;
},
onSaved: (String dob) {
_dob = dob;
}),

// getTextField("Enter first name", etFirstname, _firsNnameFocus),
// getTextField("Enter last name", etLastname, _lastNameFocus),
// getTextField("DD-MM-YYYY", etDob, _dobFocus),
GestureDetector(
onTap: () {
TextFormField(
decoration: InputDecoration(labelText: "Address"),
keyboardType: TextInputType.text,
autofocus: false,
controller: etAddress,
textInputAction: TextInputAction.done,
validator: (address) {
if (address.isEmpty) {
return 'Please enter Address';
}
return null;
},
onSaved: (String address) {
_address = address;
}),
Container(
padding: EdgeInsets.all(5.0),
alignment: Alignment.center,
child: RaisedButton(
color: Colors.pinkAccent,
onPressed: () {
addRecord(isEdit);
_myHomePageState.displayRecord();
Navigator.of(context).pop();
},
child: Container(
margin: EdgeInsets.fromLTRB(10.0, 0.0, 10.0, 0.0),
child: getAppBorderButton(isEdit ? "Edit" : "Add",
EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 0.0)),
child: Text(
isEdit ? "Update" : "Add",
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.white),
),
),
],
)),
)),

/*GestureDetector(
onTap: () {
addRecord(isEdit);
_myHomePageState.displayRecord();
Navigator.of(context).pop();
},
child: Container(
margin: EdgeInsets.fromLTRB(10.0, 0.0, 10.0, 0.0),
child: getAppBorderButton(isEdit ? "Edit" : "Add",
EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 0.0)),
),
),*/
],
)),
);
}

//focus from one field to other field
_fieldFocusChange(BuildContext context, FocusNode currentFocus,
FocusNode nextFocus) {
_fieldFocusChange(
BuildContext context, FocusNode currentFocus, FocusNode nextFocus) {
currentFocus.unfocus();
FocusScope.of(context).requestFocus(nextFocus);
}
Expand Down Expand Up @@ -180,7 +185,7 @@ class AddUserDialog {
//add/ edit user details
Future addRecord(bool isEdit) async {
var db = DatabaseHelper();
var user = User(etFirstname.text, etLastname.text, etDob.text);
var user = User(etFirstname.text, etLastname.text, etAddress.text);
if (isEdit) {
user.setUserId(this.user.id);
await db.update(user);
Expand Down
6 changes: 3 additions & 3 deletions lib/database/databasehelper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class DatabaseHelper {
void _onCreate(Database db, int version) async {
//when creating the db create the table
await db.execute(
"CREATE TABLE User(id INTEGER PRIMARY KEY, firstname TEXT, lastname TEXT, dob TEXT)");
"CREATE TABLE User(id INTEGER PRIMARY KEY, firstname TEXT, lastname TEXT, address TEXT)");
}

//save user
Expand All @@ -58,8 +58,8 @@ class DatabaseHelper {

//list of user
for (int i = 0; i < list.length; i++) {
var user =
new User(list[i]["firstname"], list[i]["lastname"], list[i]["dob"]);
var user = new User(
list[i]["firstname"], list[i]["lastname"], list[i]["address"]);
user.setUserId(list[i]["id"]);
users.add(user);
}
Expand Down
53 changes: 43 additions & 10 deletions lib/database/list_user.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:fluttercomponent_demo/database/database_presenter.dart';
Expand Down Expand Up @@ -26,13 +27,14 @@ class UsersList extends StatelessWidget {
return Card(
elevation: 5.0,
child: Container(
padding: EdgeInsets.all(5.0),
child: Center(
child: Row(
children: <Widget>[
CircleAvatar(
radius: 30.0,
child: Text(getShortName(users[index])),
backgroundColor: const Color(0xFF20283e),
backgroundColor: Colors.black,
),
Expanded(
child: Padding(
Expand All @@ -49,10 +51,10 @@ class UsersList extends StatelessWidget {
TextStyle(fontSize: 20.0, color: Colors.blue),
),
Text(
"DATE: " + users[index].dob,
"Address: " + users[index].address,
// set some style to text
style: TextStyle(
fontSize: 20.0, color: Colors.pinkAccent),
style:
TextStyle(fontSize: 20.0, color: Colors.blue),
),
],
),
Expand All @@ -67,11 +69,43 @@ class UsersList extends StatelessWidget {
onPressed: () => edit(users[index], context),
),
IconButton(
icon: const Icon(Icons.delete),
color: Colors.pinkAccent,
onPressed: () =>
dataBasePresenter.delete(users[index]),
)
icon: const Icon(Icons.delete),
color: Colors.pinkAccent,
onPressed: () => showDialog(
context: context,
barrierDismissible: false,
child: CupertinoAlertDialog(
content: new Text(
"Are you sure you want to delete?",
style: new TextStyle(fontSize: 16.0),
),
actions: <Widget>[
//login button submit click
FlatButton(
onPressed: () {
dataBasePresenter
.delete(users[index]);
//dissmiss confirmation dialog
Navigator.of(context,
rootNavigator: true)
.pop("Discard");
/* Navigator.pop(context, true);
_clearPreference(context);*/
},
child: Text("Yes")),
FlatButton(
onPressed: () {
//ok button click
//discard the alert dialog.
// Navigator.pop(context, 'Discard');
Navigator.of(context,
rootNavigator: true)
.pop("Discard");
},
child: Text("No"),
)
],
)))
],
)
],
Expand Down Expand Up @@ -103,7 +137,6 @@ class UsersList extends StatelessWidget {
shortName = user.firstName.substring(0, 1) + ".";
print(user.firstName);
print(user.lastName);

}

if (!user.lastName.isEmpty) {
Expand Down
Loading

0 comments on commit d4e0613

Please sign in to comment.