diff --git a/lib/provider/address_provider.dart b/lib/provider/address_provider.dart new file mode 100644 index 0000000..e99c980 --- /dev/null +++ b/lib/provider/address_provider.dart @@ -0,0 +1,66 @@ +import 'package:flutter/cupertino.dart'; +import 'package:store_app/src/models/address.dart'; + +class AddressProvider with ChangeNotifier { + List
_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
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(); + } +} diff --git a/lib/route_generator.dart b/lib/route_generator.dart index 32959ab..6be2fb4 100644 --- a/lib/route_generator.dart +++ b/lib/route_generator.dart @@ -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': diff --git a/lib/src/models/address.dart b/lib/src/models/address.dart index b5d8c38..6947ba6 100644 --- a/lib/src/models/address.dart +++ b/lib/src/models/address.dart @@ -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
addressFromJson(String str) => @@ -10,25 +8,26 @@ List
addressFromJson(String str) => String addressToJson(List
data) => json.encode(List.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 json) => Address( fullName: json["full_name"] == null ? null : json["full_name"], streetAddress1: @@ -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"], ); @@ -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, }; } diff --git a/lib/src/models/savedaddress.dart b/lib/src/models/savedaddress.dart deleted file mode 100644 index d8a3962..0000000 --- a/lib/src/models/savedaddress.dart +++ /dev/null @@ -1,19 +0,0 @@ -import 'package:flutter/foundation.dart'; - -class SavedAddress { - final String fullname; - final double mnumber; - final String streetaddress; - final String city; - final String state; - final double pincode; - - SavedAddress({ - @required this.fullname, - @required this.mnumber, - @required this.streetaddress, - @required this.city, - @required this.state, - @required this.pincode, - }); -} diff --git a/lib/src/screens/edit_address_screen.dart b/lib/src/screens/edit_address_screen.dart new file mode 100644 index 0000000..2c96425 --- /dev/null +++ b/lib/src/screens/edit_address_screen.dart @@ -0,0 +1,452 @@ +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import '../../config/ui_icons.dart'; +import 'package:store_app/provider/address_provider.dart'; + +import '../models/address.dart'; + +class EditAddressScreen extends StatefulWidget { + static const routeName = '/edit-address'; + + @override + _EditAddressScreenState createState() => _EditAddressScreenState(); +} + +class _EditAddressScreenState extends State { + final _phoneFocusNode = FocusNode(); + final _streetAddress1FocusNode = FocusNode(); + final _streetAddress2FocusNode = FocusNode(); + final _cityFocusNode = FocusNode(); + final _stateFocusNode = FocusNode(); + final _postalcodeFocusNode = FocusNode(); + final _form = GlobalKey(); + var _editedAddress = Address( + id: null, + fullName: '', + phone: 0, + streetAddress1: '', + streetAddress2: '', + city: '', + state: '', + postalcode: 0, + ); + var _initValues = { + 'fullName': '', + 'phone': '', + 'streetAddress1': '', + 'streetAddress2': '', + 'city': '', + 'state': '', + 'postalcode': '', + }; + var _isInit = true; + + @override + void initState() { + // _imageUrlFocusNode.addListener(_updateImageUrl); + super.initState(); + } + + @override + void didChangeDependencies() { + if (_isInit) { + final addressId = ModalRoute.of(context).settings.arguments as String; + if (addressId != null) { + _editedAddress = Provider.of(context, listen: false) + .findById(addressId); + _initValues = { + 'fullName': _editedAddress.fullName, + 'phone': _editedAddress.phone.toString(), + 'streetAddress1': _editedAddress.streetAddress1, + 'streetAddress2': _editedAddress.streetAddress2, + 'city': _editedAddress.city, + 'state': _editedAddress.state, + 'postalcode': _editedAddress.postalcode.toString(), + }; + //_imageUrlController.text = _editedProduct.imageUrl; + } + } + _isInit = false; + super.didChangeDependencies(); + } + + @override + void dispose() { + _phoneFocusNode.dispose(); + _streetAddress1FocusNode.dispose(); + _streetAddress2FocusNode.dispose(); + _cityFocusNode.dispose(); + _stateFocusNode.dispose(); + _postalcodeFocusNode.dispose(); + + super.dispose(); + } + + void _saveForm() { + final isValid = _form.currentState.validate(); + if (!isValid) { + return; + } + _form.currentState.save(); + if (_editedAddress.id != null) { + Provider.of(context, listen: false) + .updateAddress(_editedAddress.id, _editedAddress); + } else { + Provider.of(context, listen: false) + .addAddress(_editedAddress); + } + Navigator.of(context).pop(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text('Edit Address'), + actions: [ + IconButton( + icon: Icon(Icons.save), + onPressed: _saveForm, + ), + ], + ), + body: Padding( + padding: const EdgeInsets.all(16.0), + child: Form( + key: _form, + child: ListView( + children: [ + TextFormField( + initialValue: _initValues['fullName'], + decoration: InputDecoration( + hintText: 'Full Name', + hintStyle: Theme.of(context).textTheme.bodyText2.merge( + TextStyle(color: Theme.of(context).accentColor), + ), + enabledBorder: UnderlineInputBorder( + borderSide: BorderSide( + color: + Theme.of(context).accentColor.withOpacity(0.2))), + focusedBorder: UnderlineInputBorder( + borderSide: + BorderSide(color: Theme.of(context).accentColor)), + prefixIcon: Icon( + UiIcons.user_2, + color: Theme.of(context).accentColor, + ), + ), + textInputAction: TextInputAction.next, + onFieldSubmitted: (_) { + FocusScope.of(context).requestFocus(_phoneFocusNode); + }, + validator: (value) { + if (value.isEmpty) { + return 'Enter Full Name'; + } + return null; + }, + onSaved: (value) { + _editedAddress = Address( + id: _editedAddress.id, + fullName: value, + phone: _editedAddress.phone, + streetAddress1: _editedAddress.streetAddress1, + streetAddress2: _editedAddress.streetAddress2, + city: _editedAddress.city, + state: _editedAddress.state, + postalcode: _editedAddress.postalcode); + }, + ), + SizedBox(height: 10), + TextFormField( + initialValue: _initValues['phone'], + decoration: InputDecoration( + hintText: 'Phone', + hintStyle: Theme.of(context).textTheme.bodyText2.merge( + TextStyle(color: Theme.of(context).accentColor), + ), + enabledBorder: UnderlineInputBorder( + borderSide: BorderSide( + color: + Theme.of(context).accentColor.withOpacity(0.2))), + focusedBorder: UnderlineInputBorder( + borderSide: + BorderSide(color: Theme.of(context).accentColor)), + prefixIcon: Icon( + UiIcons.smartphone, + color: Theme.of(context).accentColor, + ), + ), + textInputAction: TextInputAction.next, + keyboardType: TextInputType.phone, + focusNode: _phoneFocusNode, + onFieldSubmitted: (_) { + FocusScope.of(context).requestFocus(_streetAddress1FocusNode); + }, + validator: (value) { + final numericRegex = + RegExp(r'^-?(([0-9]*)|(([0-9]*)\.([0-9]*)))$'); + if (value.length != 10 || !numericRegex.hasMatch(value)) { + return "Enter correct Mobile Number"; + } + return null; + }, + onSaved: (value) { + _editedAddress = Address( + id: _editedAddress.id, + fullName: _editedAddress.fullName, + phone: double.parse(value), + streetAddress1: _editedAddress.streetAddress1, + streetAddress2: _editedAddress.streetAddress2, + city: _editedAddress.city, + state: _editedAddress.state, + postalcode: _editedAddress.postalcode); + }, + ), + SizedBox(height: 10), + TextFormField( + initialValue: _initValues['streetAddress1'], + decoration: InputDecoration( + hintText: 'House No.,Building Name', + hintStyle: Theme.of(context).textTheme.bodyText2.merge( + TextStyle(color: Theme.of(context).accentColor), + ), + enabledBorder: UnderlineInputBorder( + borderSide: BorderSide( + color: + Theme.of(context).accentColor.withOpacity(0.2))), + focusedBorder: UnderlineInputBorder( + borderSide: + BorderSide(color: Theme.of(context).accentColor)), + prefixIcon: Icon( + UiIcons.smartphone, + color: Theme.of(context).accentColor, + ), + ), + textInputAction: TextInputAction.next, + //keyboardType: TextInputType.text, + focusNode: _streetAddress1FocusNode, + onFieldSubmitted: (_) { + FocusScope.of(context).requestFocus(_streetAddress2FocusNode); + }, + validator: (value) { + if (value.isEmpty) { + return 'Enter House No.,Building Name'; + } + return null; + }, + onSaved: (value) { + _editedAddress = Address( + id: _editedAddress.id, + fullName: _editedAddress.fullName, + phone: _editedAddress.phone, + streetAddress1: value, + streetAddress2: _editedAddress.streetAddress2, + city: _editedAddress.city, + state: _editedAddress.state, + postalcode: _editedAddress.postalcode); + }, + ), + SizedBox(height: 10), + TextFormField( + initialValue: _initValues['streetAddress2'], + decoration: InputDecoration( + hintText: 'Street Name/Area Name/Colony Name', + hintStyle: Theme.of(context).textTheme.bodyText2.merge( + TextStyle(color: Theme.of(context).accentColor), + ), + enabledBorder: UnderlineInputBorder( + borderSide: BorderSide( + color: + Theme.of(context).accentColor.withOpacity(0.2))), + focusedBorder: UnderlineInputBorder( + borderSide: + BorderSide(color: Theme.of(context).accentColor)), + prefixIcon: Icon( + UiIcons.smartphone, + color: Theme.of(context).accentColor, + ), + ), + textInputAction: TextInputAction.next, + //keyboardType: TextInputType.number, + focusNode: _streetAddress2FocusNode, + onFieldSubmitted: (_) { + FocusScope.of(context).requestFocus(_cityFocusNode); + }, + validator: (value) { + if (value.isEmpty) { + return 'Enter Street Name/Area Name/Colony Name'; + } + return null; + }, + onSaved: (value) { + _editedAddress = Address( + id: _editedAddress.id, + fullName: _editedAddress.fullName, + phone: _editedAddress.phone, + streetAddress1: _editedAddress.streetAddress1, + streetAddress2: value, + city: _editedAddress.city, + state: _editedAddress.state, + postalcode: _editedAddress.postalcode); + }, + ), + SizedBox(height: 10), + TextFormField( + initialValue: _initValues['city'], + decoration: InputDecoration( + hintText: 'Enter City/District', + hintStyle: Theme.of(context).textTheme.bodyText2.merge( + TextStyle(color: Theme.of(context).accentColor), + ), + enabledBorder: UnderlineInputBorder( + borderSide: BorderSide( + color: + Theme.of(context).accentColor.withOpacity(0.2))), + focusedBorder: UnderlineInputBorder( + borderSide: + BorderSide(color: Theme.of(context).accentColor)), + prefixIcon: Icon( + UiIcons.smartphone, + color: Theme.of(context).accentColor, + ), + ), + textInputAction: TextInputAction.next, + //keyboardType: TextInputType.number, + focusNode: _cityFocusNode, + onFieldSubmitted: (_) { + FocusScope.of(context).requestFocus(_stateFocusNode); + }, + validator: (value) { + if (value.isEmpty) { + return 'Enter City/District'; + } + return null; + }, + onSaved: (value) { + _editedAddress = Address( + id: _editedAddress.id, + fullName: _editedAddress.fullName, + phone: _editedAddress.phone, + streetAddress1: _editedAddress.streetAddress1, + streetAddress2: _editedAddress.streetAddress2, + city: value, + state: _editedAddress.state, + postalcode: _editedAddress.postalcode); + }, + ), + SizedBox(height: 10), + TextFormField( + initialValue: _initValues['state'], + decoration: InputDecoration( + hintText: 'State', + hintStyle: Theme.of(context).textTheme.bodyText2.merge( + TextStyle(color: Theme.of(context).accentColor), + ), + enabledBorder: UnderlineInputBorder( + borderSide: BorderSide( + color: + Theme.of(context).accentColor.withOpacity(0.2))), + focusedBorder: UnderlineInputBorder( + borderSide: + BorderSide(color: Theme.of(context).accentColor)), + prefixIcon: Icon( + UiIcons.smartphone, + color: Theme.of(context).accentColor, + ), + ), + textInputAction: TextInputAction.next, + //keyboardType: TextInputType.number, + focusNode: _stateFocusNode, + onFieldSubmitted: (_) { + FocusScope.of(context).requestFocus(_postalcodeFocusNode); + }, + validator: (value) { + if (value.isEmpty) { + return 'Enter State'; + } + return null; + }, + onSaved: (value) { + _editedAddress = Address( + id: _editedAddress.id, + fullName: _editedAddress.fullName, + phone: _editedAddress.phone, + streetAddress1: _editedAddress.streetAddress1, + streetAddress2: _editedAddress.streetAddress2, + city: _editedAddress.city, + state: value, + postalcode: _editedAddress.postalcode); + }, + ), + SizedBox(height: 10), + TextFormField( + initialValue: _initValues['postalcode'], + decoration: InputDecoration( + hintText: 'Postal Code(6 Digit)', + hintStyle: Theme.of(context).textTheme.bodyText2.merge( + TextStyle(color: Theme.of(context).accentColor), + ), + enabledBorder: UnderlineInputBorder( + borderSide: BorderSide( + color: + Theme.of(context).accentColor.withOpacity(0.2))), + focusedBorder: UnderlineInputBorder( + borderSide: + BorderSide(color: Theme.of(context).accentColor)), + prefixIcon: Icon( + UiIcons.smartphone, + color: Theme.of(context).accentColor, + ), + ), + textInputAction: TextInputAction.next, + keyboardType: TextInputType.number, + focusNode: _postalcodeFocusNode, + onFieldSubmitted: (_) { + _saveForm(); + }, + validator: (value) { + final numericRegex = + RegExp(r'^-?(([0-9]*)|(([0-9]*)\.([0-9]*)))$'); + if (value.length != 6 || !numericRegex.hasMatch(value)) { + return "Enter correct Postal Code"; + } + return null; + }, + onSaved: (value) { + _editedAddress = Address( + id: _editedAddress.id, + fullName: _editedAddress.fullName, + phone: _editedAddress.phone, + streetAddress1: _editedAddress.streetAddress1, + streetAddress2: _editedAddress.streetAddress2, + city: _editedAddress.city, + state: _editedAddress.state, + postalcode: double.parse(value)); + }, + ), + SizedBox(height: 50), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + FlatButton( + padding: EdgeInsets.symmetric(vertical: 12, horizontal: 70), + onPressed: _saveForm, + child: Text( + 'Save Address', + style: Theme.of(context).textTheme.title.merge( + TextStyle(color: Theme.of(context).backgroundColor), + ), + ), + color: Theme.of(context).accentColor, + shape: StadiumBorder(), + ), + ], + ) + ], + ), + ), + ), + ); + } +} diff --git a/lib/src/screens/shippingaddressmain.dart b/lib/src/screens/shippingaddressmain.dart index a2cb723..9bd96a8 100644 --- a/lib/src/screens/shippingaddressmain.dart +++ b/lib/src/screens/shippingaddressmain.dart @@ -1,90 +1,116 @@ -import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; -import '../widgets/new_address.dart'; -import '../models/savedaddress.dart'; -import '../widgets/address_list.dart'; +import 'package:store_app/config/app_config.dart' as config; +import 'package:provider/provider.dart'; +import 'package:store_app/provider/address_provider.dart'; +import 'package:store_app/src/models/user.dart'; +import 'package:store_app/src/screens/user_address_screen.dart'; -void main() => runApp(MyApp()); +import 'edit_address_screen.dart'; -class MyApp extends StatelessWidget { - @override - Widget build(BuildContext context) { - return MaterialApp( - title: 'Saved Address ', - home: MyHomePage(), - ); - } -} - -class MyHomePage extends StatefulWidget { - @override - _MyHomePageState createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State { - final List _userAddress = [ - SavedAddress( - fullname: 'Naraka  Parmar', - mnumber: 8767546789, - streetaddress: 'Tilak Rd, Opp Mahad Coop Bank, Panvel, Navi Mumbai', - city: 'Mumbai', - state: 'Maharashtra', - pincode: 401206), - SavedAddress( - fullname: 'Apala  Nagy', - mnumber: 87657657654, - streetaddress: '1452 /, Wazir Nagar, Kotla Mubarakpur', - city: 'Delhi', - state: 'delhi', - pincode: 110003), - ]; - void _addNewAddress(String sdfullname, double sdmnumber, - String sdstreetaddress, String sdcity, String sdstate, double sdpincode) { - final newSd = SavedAddress( - fullname: sdfullname, - mnumber: sdmnumber, - streetaddress: sdstreetaddress, - city: sdcity, - state: sdstate, - pincode: sdpincode); - setState(() { - _userAddress.add(newSd); - }); - } - - void _startAddNewAddress(BuildContext ctx) { - showModalBottomSheet( - context: ctx, - builder: (_) { - return GestureDetector( - onTap: () {}, - child: NewAddress(_addNewAddress), - behavior: HitTestBehavior.opaque, - ); - }, - ); - } +void main() => runApp(MyAddress()); +class MyAddress extends StatelessWidget { @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text('Shipping Address'), - ), - body: SingleChildScrollView( - child: Column( - //mainAxisAlignment: MainAxisAlignment.spaceAround, - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [AddressList(_userAddress)], - ), - ), - floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, - floatingActionButton: FloatingActionButton.extended( - //icon: Icon(Icons.add), - label: Text('Add New Address'), - - onPressed: () => _startAddNewAddress(context), - ), + return ChangeNotifierProvider( + create: (ctx) => AddressProvider(), + child: MaterialApp( + darkTheme: ThemeData( + fontFamily: 'Poppins', + primaryColor: Color(0xFF252525), + brightness: Brightness.dark, + scaffoldBackgroundColor: Color(0xFF2C2C2C), + accentColor: config.Colors().mainDarkColor(1), + hintColor: config.Colors().secondDarkColor(1), + focusColor: config.Colors().accentDarkColor(1), + textTheme: TextTheme( + button: TextStyle(color: Color(0xFF252525)), + headline: TextStyle( + fontSize: 20.0, color: config.Colors().secondDarkColor(1)), + display1: TextStyle( + fontSize: 18.0, + fontWeight: FontWeight.w600, + color: config.Colors().secondDarkColor(1)), + display2: TextStyle( + fontSize: 20.0, + fontWeight: FontWeight.w600, + color: config.Colors().secondDarkColor(1)), + display3: TextStyle( + fontSize: 22.0, + fontWeight: FontWeight.w700, + color: config.Colors().mainDarkColor(1)), + display4: TextStyle( + fontSize: 22.0, + fontWeight: FontWeight.w300, + color: config.Colors().secondDarkColor(1)), + subhead: TextStyle( + fontSize: 15.0, + fontWeight: FontWeight.w500, + color: config.Colors().secondDarkColor(1)), + title: TextStyle( + fontSize: 16.0, + fontWeight: FontWeight.w600, + color: config.Colors().mainDarkColor(1)), + body1: TextStyle( + fontSize: 12.0, color: config.Colors().secondDarkColor(1)), + body2: TextStyle( + fontSize: 14.0, + fontWeight: FontWeight.w600, + color: config.Colors().secondDarkColor(1)), + caption: TextStyle( + fontSize: 12.0, color: config.Colors().secondDarkColor(0.7)), + ), + ), + theme: ThemeData( + fontFamily: 'Poppins', + primaryColor: Colors.white, + brightness: Brightness.light, + accentColor: config.Colors().mainColor(1), + focusColor: config.Colors().accentColor(1), + hintColor: config.Colors().secondColor(1), + textTheme: TextTheme( + button: TextStyle(color: Colors.white), + headline: TextStyle( + fontSize: 20.0, color: config.Colors().secondColor(1)), + display1: TextStyle( + fontSize: 18.0, + fontWeight: FontWeight.w600, + color: config.Colors().secondColor(1)), + display2: TextStyle( + fontSize: 20.0, + fontWeight: FontWeight.w600, + color: config.Colors().secondColor(1)), + display3: TextStyle( + fontSize: 22.0, + fontWeight: FontWeight.w700, + color: config.Colors().mainColor(1)), + display4: TextStyle( + fontSize: 22.0, + fontWeight: FontWeight.w300, + color: config.Colors().secondColor(1)), + subhead: TextStyle( + fontSize: 15.0, + fontWeight: FontWeight.w500, + color: config.Colors().secondColor(1)), + title: TextStyle( + fontSize: 16.0, + fontWeight: FontWeight.w600, + color: config.Colors().mainColor(1)), + body1: TextStyle( + fontSize: 12.0, color: config.Colors().secondColor(1)), + body2: TextStyle( + fontSize: 14.0, + fontWeight: FontWeight.w600, + color: config.Colors().secondColor(1)), + caption: TextStyle( + fontSize: 12.0, color: config.Colors().secondColor(0.6)), + ), + ), + home: UserAddressScreen(), + routes: { + EditAddressScreen.routeName: (ctx) => EditAddressScreen(), + //UserAddressScreen.routeName: (ctx) => UserAddressScreen(), + }), ); } } diff --git a/lib/src/screens/user_address_screen.dart b/lib/src/screens/user_address_screen.dart new file mode 100644 index 0000000..c6be9b8 --- /dev/null +++ b/lib/src/screens/user_address_screen.dart @@ -0,0 +1,95 @@ +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:store_app/provider/address_provider.dart'; + +import '../widgets/user_address_item.dart'; +import './edit_address_screen.dart'; +import '../widgets/DrawerWidget.dart'; +import '../widgets/ShoppingCartButtonWidget.dart'; + +class UserAddressScreen extends StatelessWidget { + final GlobalKey _scaffoldKey = new GlobalKey(); + static const routeName = '/user-address'; + @override + Widget build(BuildContext context) { + final addressData = Provider.of(context); + return Scaffold( + key: _scaffoldKey, + drawer: DrawerWidget(), + appBar: AppBar( + automaticallyImplyLeading: false, +// leading: new IconButton( +// icon: new Icon(UiIcons.return_icon, color: Theme.of(context).hintColor), +// onPressed: () => Navigator.of(context).pop(), +// ), + leading: new IconButton( + icon: new Icon(Icons.sort, color: Theme.of(context).hintColor), + onPressed: () => _scaffoldKey.currentState.openDrawer(), + ), + backgroundColor: Colors.transparent, + elevation: 0, + title: Text( + 'Address', + style: Theme.of(context).textTheme.display1, + ), + actions: [ + new ShoppingCartButtonWidget( + iconColor: Theme.of(context).hintColor, + labelColor: Theme.of(context).accentColor), + Container( + width: 30, + height: 30, + margin: EdgeInsets.only(top: 12.5, bottom: 12.5, right: 20), + child: InkWell( + borderRadius: BorderRadius.circular(300), + onTap: () { + Navigator.of(context).pushNamed('/Tabs', arguments: 1); + }, + child: CircleAvatar( + backgroundImage: AssetImage('img/user2.jpg'), + ), + )), + ], + ), + /*appBar: AppBar( + title: const Text('Your Address'), + actions: [ + IconButton( + onPressed: () { + Navigator.of(context).pushNamed(EditAddressScreen.routeName); + }, + icon: Icon(Icons.add), + ) + ], + ),*/ + body: Padding( + padding: EdgeInsets.all(8), + child: ListView.builder( + itemCount: addressData.items.length, + itemBuilder: (_, i) => Column( + children: [ + UserAddressItem( + addressData.items[i].id, + addressData.items[i].fullName, + addressData.items[i].phone.toString(), + addressData.items[i].streetAddress1, + addressData.items[i].streetAddress2, + addressData.items[i].city, + addressData.items[i].state, + addressData.items[i].postalcode), + Divider(), + ], + ), + ), + ), + floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, + floatingActionButton: FloatingActionButton.extended( + //icon: Icon(Icons.add), + onPressed: () { + Navigator.of(context).pushNamed(EditAddressScreen.routeName); + }, + label: Text('Add New Address'), + ), + ); + } +} diff --git a/lib/src/widgets/address_list.dart b/lib/src/widgets/address_list.dart deleted file mode 100644 index c56e24c..0000000 --- a/lib/src/widgets/address_list.dart +++ /dev/null @@ -1,42 +0,0 @@ -import 'package:flutter/material.dart'; -import '../models/savedaddress.dart'; - -class AddressList extends StatelessWidget { - final List address; - AddressList(this.address); - - @override - Widget build(BuildContext context) { - return Container( - height: 300, - child: ListView.builder( - itemBuilder: (ctx, index) { - return Container( - width: double.infinity, - child: Card( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - address[index].fullname, - style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), - ), - Text( - address[index].mnumber.toString(), - style: TextStyle(color: Colors.grey), - ), - Text(address[index].streetaddress), - Text(address[index].city), - Text(address[index].state), - Text(address[index].pincode.toString()) - ], - ), - ), - ); - }, - itemCount: address.length, - // children: address.map((sd) { }).toList(), - ), - ); - } -} diff --git a/lib/src/widgets/user_address_item.dart b/lib/src/widgets/user_address_item.dart new file mode 100644 index 0000000..7feca82 --- /dev/null +++ b/lib/src/widgets/user_address_item.dart @@ -0,0 +1,75 @@ +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:store_app/provider/address_provider.dart'; + +import '../screens/edit_address_screen.dart'; + +class UserAddressItem extends StatelessWidget { + final String id; + final String fullName; + final String phone; + final String streetAddress1; + final String streetAddress2; + final String city; + final String state; + final double postalcode; + + UserAddressItem(this.id, this.fullName, this.phone, this.streetAddress1, + this.streetAddress2, this.city, this.state, this.postalcode); + + @override + Widget build(BuildContext context) { + return ListTile( + title: Card( + elevation: 5, + child: Container( + padding: EdgeInsets.all(10), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + fullName, + style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), + ), + Text( + phone.toString(), + ), + Text(streetAddress1), + Text(streetAddress2), + Text(city), + Text(state), + Text(postalcode.toString()), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + MaterialButton( + onPressed: () { + Navigator.of(context).pushNamed( + EditAddressScreen.routeName, + arguments: id); + }, + child: Text( + 'Edit', + style: TextStyle(color: Theme.of(context).accentColor), + ), + ), + MaterialButton( + onPressed: () { + Provider.of(context, listen: false) + .deleteAddress(id); + }, + child: Text( + 'Delete', + style: TextStyle(color: Theme.of(context).accentColor), + ), + ), + ], + ), + ], + ), + ), + ), + //title: Text(fullName), + ); + } +}