You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.8 KiB
Dart
54 lines
1.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:test_sa/extensions/context_extension.dart';
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
import 'package:test_sa/modules/alerts/alert_item_view.dart';
|
|
import 'package:test_sa/modules/alerts/alert_provider.dart';
|
|
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
|
|
import 'package:test_sa/views/widgets/loaders/lazy_loading.dart';
|
|
import 'package:test_sa/views/widgets/loaders/no_data_found.dart';
|
|
|
|
class AlertsListPage extends StatefulWidget {
|
|
const AlertsListPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<AlertsListPage> createState() => _AlertsListPageState();
|
|
}
|
|
|
|
class _AlertsListPageState extends State<AlertsListPage> {
|
|
AlertProvider? _provider;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
_provider = Provider.of<AlertProvider>(context);
|
|
if (_provider!.items == null && !_provider!.isLoading) {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
_provider!.reset();
|
|
_provider!.getAlerts();
|
|
});
|
|
}
|
|
|
|
return Consumer<AlertProvider>(builder: (context, snapshot, _) {
|
|
final list = snapshot.items ?? [];
|
|
if (list.isEmpty && !snapshot.isLoading) {
|
|
return NoDataFound(message: context.translation.noDataFound).center;
|
|
}
|
|
return LazyLoading(
|
|
nextPage: snapshot.nextPage,
|
|
onLazyLoad: () async {
|
|
await snapshot.getAlerts();
|
|
},
|
|
child: ListView.separated(
|
|
padding: const EdgeInsets.all(16),
|
|
itemBuilder: (cxt, index) {
|
|
if (index >= list.length) return const SizedBox();
|
|
return AlertItemView(alert: list[index]);
|
|
},
|
|
separatorBuilder: (cxt, index) => const SizedBox(height: 12),
|
|
itemCount: list.length,
|
|
),
|
|
);
|
|
});
|
|
}
|
|
}
|