2022-12-27 03:19:49 +00:00
|
|
|
import 'package:cubit_form/cubit_form.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2022-12-27 06:39:46 +00:00
|
|
|
import 'package:selfprivacy/logic/itemformcubit.dart';
|
2022-12-27 05:29:50 +00:00
|
|
|
import 'package:selfprivacy/logic/itemscubit.dart';
|
2022-12-27 03:19:49 +00:00
|
|
|
import 'package:selfprivacy/models/item.dart';
|
2022-12-27 06:39:46 +00:00
|
|
|
import 'package:selfprivacy/ui/bottomsheet.dart';
|
|
|
|
import 'package:selfprivacy/ui/button.dart';
|
2022-12-27 03:19:49 +00:00
|
|
|
|
|
|
|
part 'item.dart';
|
2022-12-27 06:37:39 +00:00
|
|
|
part 'itemsdetails.dart';
|
2022-12-27 03:19:49 +00:00
|
|
|
|
|
|
|
class ItemsPage extends StatelessWidget {
|
|
|
|
const ItemsPage({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(final BuildContext context) {
|
|
|
|
final Widget child = BlocBuilder<ItemsCubit, ItemsState>(
|
|
|
|
builder: (final BuildContext context, final ItemsState state) {
|
2022-12-27 05:29:50 +00:00
|
|
|
final List<Item> items = state.items;
|
2022-12-27 03:19:49 +00:00
|
|
|
|
2022-12-27 05:29:50 +00:00
|
|
|
if (items.isEmpty) {
|
2022-12-27 03:19:49 +00:00
|
|
|
if (state.isLoading) {
|
|
|
|
return const Center(
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return RefreshIndicator(
|
|
|
|
onRefresh: () async {
|
|
|
|
context.read<ItemsCubit>().refresh();
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 15),
|
|
|
|
child: Center(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
ConstrainedBox(
|
|
|
|
constraints: const BoxConstraints(
|
|
|
|
minHeight: 40,
|
|
|
|
minWidth: double.infinity,
|
|
|
|
),
|
|
|
|
child: OutlinedButton(
|
|
|
|
onPressed: () {
|
|
|
|
context.read<ItemsCubit>().refresh();
|
|
|
|
},
|
|
|
|
child: Text(
|
|
|
|
'Обновить',
|
|
|
|
style: Theme.of(context).textTheme.button?.copyWith(
|
|
|
|
color: Theme.of(context).colorScheme.primary,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return RefreshIndicator(
|
|
|
|
onRefresh: () async {
|
|
|
|
context.read<ItemsCubit>().refresh();
|
|
|
|
},
|
|
|
|
child: ListView.builder(
|
2022-12-27 05:29:50 +00:00
|
|
|
itemCount: items.length,
|
2022-12-27 03:19:49 +00:00
|
|
|
itemBuilder: (final BuildContext context, final int index) => _Item(
|
2022-12-27 05:29:50 +00:00
|
|
|
item: items[index],
|
2022-12-27 03:19:49 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
appBar: PreferredSize(
|
|
|
|
preferredSize: const Size.fromHeight(52),
|
|
|
|
child: AppBar(
|
|
|
|
title: const Padding(
|
|
|
|
padding: EdgeInsets.only(top: 4.0),
|
|
|
|
child: Text('Товары'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
body: child,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|