feat: make server own products
This commit is contained in:
@@ -9,6 +9,8 @@ import '../l10n/app_localizations_helpers.dart';
|
||||
import '../utils/money.dart';
|
||||
import '../utils/navigation.dart';
|
||||
import '../viewmodels/product_list_view_model.dart';
|
||||
import '../viewmodels/remote_sync_view_model.dart';
|
||||
import 'widgets/managed_on_website_notice.dart';
|
||||
|
||||
class ProductListView extends StatefulWidget {
|
||||
const ProductListView({super.key});
|
||||
@@ -31,6 +33,8 @@ class _ProductListViewState extends State<ProductListView> {
|
||||
Widget build(BuildContext context) {
|
||||
final viewModel = context.watch<ProductListViewModel>();
|
||||
final l10n = AppLocalizations.of(context);
|
||||
// A paired tablet gets its products from the website
|
||||
final managedOnWebsite = context.watch<RemoteSyncViewModel>().isConfigured;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
@@ -41,11 +45,13 @@ class _ProductListViewState extends State<ProductListView> {
|
||||
title: Text(l10n.products),
|
||||
),
|
||||
resizeToAvoidBottomInset: false,
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () => context.push('/products/new'),
|
||||
icon: const Icon(Icons.add),
|
||||
label: Text(l10n.addProduct),
|
||||
),
|
||||
floatingActionButton: managedOnWebsite
|
||||
? null
|
||||
: FloatingActionButton.extended(
|
||||
onPressed: () => context.push('/products/new'),
|
||||
icon: const Icon(Icons.add),
|
||||
label: Text(l10n.addProduct),
|
||||
),
|
||||
body: Builder(
|
||||
builder: (context) {
|
||||
if (viewModel.isLoading) {
|
||||
@@ -56,16 +62,19 @@ class _ProductListViewState extends State<ProductListView> {
|
||||
return Center(child: Text(l10n.errorText(viewModel.loadError)));
|
||||
}
|
||||
|
||||
if (viewModel.products.isEmpty) {
|
||||
if (viewModel.products.isEmpty && !managedOnWebsite) {
|
||||
return Center(child: Text(l10n.noProductsYet));
|
||||
}
|
||||
|
||||
// The notice takes the first row
|
||||
final offset = managedOnWebsite ? 1 : 0;
|
||||
return ListView.separated(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: viewModel.products.length,
|
||||
itemCount: viewModel.products.length + offset,
|
||||
separatorBuilder: (_, _) => const SizedBox(height: 8),
|
||||
itemBuilder: (context, index) {
|
||||
final product = viewModel.products[index];
|
||||
if (index < offset) return const ManagedOnWebsiteNotice();
|
||||
final product = viewModel.products[index - offset];
|
||||
|
||||
return Card(
|
||||
child: ListTile(
|
||||
|
||||
Reference in New Issue
Block a user