-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from trunghvbk/structure
add network package
- Loading branch information
Showing
20 changed files
with
397 additions
and
100 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import 'package:flutter_app/features/products/domain/product.dart'; | ||
|
||
abstract class ProductService { | ||
Future<List<Product>> getProducts(int currentPage, int pageSize); | ||
} |
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
lib/features/products/presentation/product_list_controller.dart
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:flutter_app/features/products/application/product_service.dart'; | ||
import 'package:flutter_app/features/products/domain/product.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
class ProductListController extends StateNotifier<AsyncValue<List<Product>>> { | ||
ProductListController({required this.productService}) | ||
: super(const AsyncData([])) { | ||
loadProducts(); | ||
} | ||
final ProductService productService; | ||
|
||
Future<void> loadProducts() async { | ||
state = const AsyncLoading(); | ||
state = await AsyncValue.guard( | ||
() => productService.getProducts(0, 100), | ||
); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_app/features/products/presentation/widgets/product_list_item.dart'; | ||
import 'package:flutter_app/providers/controller_providers.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
class ProductListPage extends ConsumerWidget { | ||
const ProductListPage({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final dataValue = ref.watch(productListControllerProvider); | ||
return Scaffold( | ||
appBar: AppBar(title: const Text('Product List')), | ||
body: dataValue.when( | ||
data: (data) { | ||
return GridView.count( | ||
crossAxisCount: 2, | ||
children: data | ||
.map((product) => ProductListItem(product: product)) | ||
.toList(), | ||
); | ||
}, | ||
loading: () => const Center(child: CircularProgressIndicator()), | ||
error: (e, __) => Text(e.toString())), | ||
); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
lib/features/products/presentation/widgets/product_list_item.dart
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter_app/features/products/domain/product.dart'; | ||
|
||
class ProductListItem extends StatelessWidget { | ||
final Product product; | ||
const ProductListItem({super.key, required this.product}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
children: [ | ||
Text(product.title), | ||
Text('${product.availableQuantity}'), | ||
Text('${product.price}') | ||
], | ||
); | ||
} | ||
} |
Oops, something went wrong.