Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

address screen #17

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions lib/provider/address_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import 'package:flutter/cupertino.dart';
import 'package:store_app/src/models/address.dart';

class AddressProvider with ChangeNotifier {
List<Address> _items = [
Address(
id: '1',
fullName: 'Naraka  Parmar',
phone: 8767546789,
streetAddress1: 'Tilak Rd, Opp Mahad Coop Bank',
streetAddress2: ' Panvel, Navi Mumbai',
city: 'Mumbai',
state: 'Maharashtra',
postalcode: 401206,
),
Address(
id: '2',
fullName: 'Apala  Nagy',
phone: 87657657654,
streetAddress1: '1452 /, Wazir Nagar,',
streetAddress2: ' Kotla Mubarakpur',
city: 'Delhi',
state: 'delhi',
postalcode: 110003,
),
];

List<Address> get items {
return [..._items];
}

Address findById(String id) {
return _items.firstWhere((prod) => prod.id == id);
}

void addAddress(Address address) {
final newAddress = Address(
fullName: address.fullName,
phone: address.phone,
streetAddress1: address.streetAddress1,
streetAddress2: address.streetAddress2,
city: address.city,
state: address.state,
postalcode: address.postalcode,
id: DateTime.now().toString(),
);
_items.add(newAddress);
// _items.add(value);
notifyListeners();
}

void updateAddress(String id, Address newAddress) {
final addrIndex = _items.indexWhere((addr) => addr.id == id);
if (addrIndex >= 0) {
_items[addrIndex] = newAddress;
notifyListeners();
} else {
print('...');
}
}

void deleteAddress(String id) {
_items.removeWhere((addr) => addr.id == id);
notifyListeners();
}
}
2 changes: 1 addition & 1 deletion lib/route_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class RouteGenerator {
case '/Languages':
return MaterialPageRoute(builder: (_) => LanguagesWidget());
case '/Shipping Address':
return MaterialPageRoute(builder: (_) => MyHomePage());
return MaterialPageRoute(builder: (_) => MyAddress());
case '/Order':
return MaterialPageRoute(builder: (_) => OrderSummaryWidget());
case '/Chat':
Expand Down
35 changes: 17 additions & 18 deletions lib/src/models/address.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// To parse this JSON data, do
//
// final address = addressFromJson(jsonString);

import 'package:flutter/foundation.dart';
//import 'package:store_app/src/models/address.dart';
import 'dart:convert';

List<Address> addressFromJson(String str) =>
Expand All @@ -10,25 +8,26 @@ List<Address> addressFromJson(String str) =>
String addressToJson(List<Address> data) =>
json.encode(List<dynamic>.from(data.map((x) => x.toJson())));

class Address {
class Address with ChangeNotifier {
String id;
String fullName;
double phone;
String streetAddress1;
String streetAddress2;
String city;
String state;
double postalcode;

Address({
this.id,
this.fullName,
this.phone,
this.streetAddress1,
this.streetAddress2,
this.city,
this.state,
this.postalCode,
this.phone,
this.postalcode,
});

String fullName;
String streetAddress1;
String streetAddress2;
String city;
String state;
String postalCode;
String phone;

factory Address.fromJson(Map<String, dynamic> json) => Address(
fullName: json["full_name"] == null ? null : json["full_name"],
streetAddress1:
Expand All @@ -37,7 +36,7 @@ class Address {
json["street_address_2"] == null ? null : json["street_address_2"],
city: json["city"] == null ? null : json["city"],
state: json["state"] == null ? null : json["state"],
postalCode: json["postal_code"] == null ? null : json["postal_code"],
postalcode: json["postal_code"] == null ? null : json["postal_code"],
phone: json["phone"] == null ? null : json["phone"],
);

Expand All @@ -47,7 +46,7 @@ class Address {
"street_address_2": streetAddress2 == null ? null : streetAddress2,
"city": city == null ? null : city,
"state": state == null ? null : state,
"postal_code": postalCode == null ? null : postalCode,
"postal_code": postalcode == null ? null : postalcode,
"phone": phone == null ? null : phone,
};
}
19 changes: 0 additions & 19 deletions lib/src/models/savedaddress.dart

This file was deleted.

Loading