88 lines
2.6 KiB
Dart
88 lines
2.6 KiB
Dart
|
import 'package:cubit_form/cubit_form.dart';
|
||
|
import 'package:flutter/material.dart';
|
||
|
import 'package:selfprivacy/models/item.dart';
|
||
|
|
||
|
part 'item.dart';
|
||
|
|
||
|
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) {
|
||
|
final List<Item> users = state.users;
|
||
|
|
||
|
if (users.isEmpty) {
|
||
|
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(
|
||
|
itemCount: users.length,
|
||
|
itemBuilder: (final BuildContext context, final int index) => _Item(
|
||
|
item: users[index],
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
},
|
||
|
);
|
||
|
|
||
|
return Scaffold(
|
||
|
appBar: PreferredSize(
|
||
|
preferredSize: const Size.fromHeight(52),
|
||
|
child: AppBar(
|
||
|
title: const Padding(
|
||
|
padding: EdgeInsets.only(top: 4.0),
|
||
|
child: Text('Товары'),
|
||
|
),
|
||
|
leading: IconButton(
|
||
|
icon: const Icon(Icons.arrow_back),
|
||
|
onPressed: () => Navigator.of(context).pop(),
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
body: child,
|
||
|
);
|
||
|
}
|
||
|
}
|