This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Future<List<Product>> _parseProductsFromResponse(int categoryId) async { | |
| List<Product> productsList = <Product>[]; | |
| var dataFromResponse = await _getProductsByCategory(categoryId, 1); | |
| dataFromResponse.forEach( | |
| (newProduct) { | |
| //parse the product's images | |
| List<AnyImage> imagesOfProductList = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FutureBuilder<List<Product>>( | |
| future: _parseProductsFromResponse(95), | |
| builder: (context, snapshot) { | |
| switch (snapshot.connectionState) { | |
| case ConnectionState.active: | |
| case ConnectionState.waiting: | |
| return Center(child: CircularProgressIndicator()); | |
| case ConnectionState.none: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| onTap: () { | |
| Navigator.of(context).push( | |
| MaterialPageRoute( | |
| builder: (context) { | |
| return ProductDetailPage(product: product); | |
| }, | |
| ), | |
| ); | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ProductDetailPage extends StatefulWidget { | |
| final Product product; | |
| ProductDetailPage({this.product}); | |
| @override | |
| _ProductDetailPageState createState() => _ProductDetailPageState(product); | |
| } | |
| class _ProductDetailPageState extends State<ProductDetailPage> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dependencies: | |
| flutter: | |
| sdk: flutter | |
| # The following adds the Cupertino Icons font to your application. | |
| # Use with the CupertinoIcons class for iOS style icons. | |
| cupertino_icons: ^0.1.2 | |
| http: ^0.11.3+16 | |
| scoped_model: ^0.2.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:scoped_model/scoped_model.dart'; | |
| class ProductScopedModel extends Model { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ProductScopedModel extends Model { | |
| List<Product> _productsList = []; | |
| bool _isLoading = true; | |
| List<Product> get productsList => _productsList; | |
| bool get isLoading => _isLoading; | |
| void addToProductsList(Product product) { | |
| _productsList.add(product); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ProductScopedModel productModel = ProductScopedModel(); | |
| productModel.parseProductsFromResponse(95, 1); | |
| return new ScopedModel<ProductScopedModel>( | |
| model: productModel, | |
| child: Scaffold( | |
| appBar: AppBar( | |
| centerTitle: true, | |
| backgroundColor: Colors.white, | |
| title: Text( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ProductsListPageBody extends StatelessWidget { | |
| BuildContext context; | |
| ProductScopedModel model; | |
| @override | |
| Widget build(BuildContext context) { | |
| this.context = context; | |
| return ScopedModelDescendant<ProductScopedModel>( | |
| builder: (context, child, model) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _buildListView() { | |
| Size screenSize = MediaQuery.of(context).size; | |
| return Padding( | |
| padding: const EdgeInsets.only(bottom: 8.0), | |
| child: model.getProductsCount() == 0 | |
| ? Center(child: Text("No products available.")) | |
| : ListView.builder( | |
| itemCount: model.getProductsCount() + 1, | |
| itemBuilder: (context, index) { |