You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.4 KiB
44 lines
1.4 KiB
import 'package:flutter/material.dart';
|
|
import 'package:thesis_shop/models/remote_resource.dart';
|
|
import 'package:thesis_shop/screens/product_list/cart_button_overlay.dart';
|
|
import 'package:thesis_shop/screens/product_list/product_list.dart';
|
|
import 'package:thesis_shop/stores/product_store.dart';
|
|
import 'package:thesis_shop/widgets/user_switch.dart';
|
|
|
|
class ProductListScreen extends StatelessWidget {
|
|
const ProductListScreen({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Thesis Shop'),
|
|
actions: const [UserSwitch()],
|
|
),
|
|
body: const _ProductStateSwitch(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _ProductStateSwitch extends StatelessWidget {
|
|
const _ProductStateSwitch({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final remoteProducts = ProductStore.of(context).products;
|
|
if (remoteProducts is FinishedRemoteResource) {
|
|
final products = remoteProducts.asFinished().value;
|
|
return CartButtonOverlay(
|
|
child: ProductList(
|
|
products: products,
|
|
),
|
|
);
|
|
} else if (remoteProducts is ErrorRemoteResource) {
|
|
return Center(child: Text(remoteProducts.asError().errorMessage));
|
|
} else if (remoteProducts is LoadingRemoteResource) {
|
|
return const Center(child: CircularProgressIndicator.adaptive());
|
|
} else {
|
|
throw UnimplementedError();
|
|
}
|
|
}
|
|
}
|
|
|