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.
182 lines
7.5 KiB
Dart
182 lines
7.5 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mohem_flutter_app/api/pending_transactions_api_client.dart';
|
|
import 'package:mohem_flutter_app/app_state/app_state.dart';
|
|
import 'package:mohem_flutter_app/classes/colors.dart';
|
|
import 'package:mohem_flutter_app/classes/utils.dart';
|
|
import 'package:mohem_flutter_app/config/routes.dart';
|
|
import 'package:mohem_flutter_app/extensions/int_extensions.dart';
|
|
import 'package:mohem_flutter_app/extensions/string_extensions.dart';
|
|
import 'package:mohem_flutter_app/models/get_announcements.dart';
|
|
import 'package:mohem_flutter_app/widgets/app_bar_widget.dart';
|
|
import 'package:mohem_flutter_app/widgets/dynamic_forms/dynamic_textfield_widget.dart';
|
|
|
|
class Announcements extends StatefulWidget {
|
|
const Announcements({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
_AnnouncementsState createState() => _AnnouncementsState();
|
|
}
|
|
|
|
class _AnnouncementsState extends State<Announcements> {
|
|
String jsonResponse = "";
|
|
int currentPageNo = 1;
|
|
int currentOpenIndex = -1;
|
|
|
|
List<GetAnnouncementsObject> getAnnouncementsObject = [];
|
|
List<GetAnnouncementsObject> _foundAnnouncements = [];
|
|
TextEditingController searchController = TextEditingController();
|
|
final ScrollController _controller = ScrollController();
|
|
|
|
@override
|
|
void initState() {
|
|
getAnnouncements(0, 0);
|
|
super.initState();
|
|
_controller.addListener(() {
|
|
if (_controller.position.atEdge) {
|
|
bool isTop = _controller.position.pixels == 0;
|
|
if (!isTop) {
|
|
print('At the bottom');
|
|
currentPageNo++;
|
|
getAnnouncements(0, 0);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.white,
|
|
appBar: AppBarWidget(
|
|
context,
|
|
title: "Announcements",
|
|
),
|
|
body: getAnnouncementsObject.isNotEmpty
|
|
? Container(
|
|
margin: const EdgeInsets.only(top: 10.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
12.height,
|
|
Container(
|
|
margin: const EdgeInsets.fromLTRB(12.0, 0.0, 12.0, 0.0),
|
|
child: DynamicTextFieldWidget(
|
|
"Search",
|
|
"Search Announcements",
|
|
isEnable: true,
|
|
suffixIconData: Icons.search,
|
|
isPopup: false,
|
|
lines: 1,
|
|
isInputTypeNum: false,
|
|
isReadOnly: false,
|
|
onChange: (String value) {
|
|
_runFilter(value);
|
|
},
|
|
),
|
|
),
|
|
12.height,
|
|
Expanded(
|
|
child: ListView.separated(
|
|
physics: const BouncingScrollPhysics(),
|
|
shrinkWrap: true,
|
|
controller: _controller,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
return InkWell(
|
|
onTap: () {
|
|
openAnnouncementsDetails(int.parse(_foundAnnouncements[index].rowID!));
|
|
},
|
|
child: Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.all(10.0),
|
|
margin: const EdgeInsets.only(left: 12, right: 12, top: 10),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(10),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: const Color(0xff000000).withOpacity(.05),
|
|
blurRadius: 26,
|
|
offset: const Offset(0, -3),
|
|
),
|
|
],
|
|
),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
SizedBox(
|
|
width: 80.0,
|
|
height: 80.0,
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.circular(10),
|
|
child: Image.memory(
|
|
base64Decode(Utils.getBase64FromJpeg(_foundAnnouncements[index].bannerImage)),
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
),
|
|
12.width,
|
|
SizedBox(
|
|
height: 80.0,
|
|
width: 200.0,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
AppState().isArabic(context) ? _foundAnnouncements[index].titleAR!.toText13() : getAnnouncementsObject[index].titleEN!.toText13(),
|
|
8.height,
|
|
_foundAnnouncements[index].created!.toText10(color: MyColors.grey98Color)
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
separatorBuilder: (BuildContext context, int index) => 1.height,
|
|
itemCount: _foundAnnouncements.length ?? 0)),
|
|
20.height,
|
|
],
|
|
),
|
|
)
|
|
: Utils.getNoDataWidget(context),
|
|
);
|
|
}
|
|
|
|
void _runFilter(String enteredKeyword) {
|
|
List<GetAnnouncementsObject> results = [];
|
|
if (enteredKeyword.isEmpty) {
|
|
results = getAnnouncementsObject;
|
|
} else {
|
|
results = getAnnouncementsObject.where((user) => user.titleEN!.toLowerCase().contains(enteredKeyword.toLowerCase())).toList();
|
|
}
|
|
setState(() {
|
|
_foundAnnouncements = results;
|
|
});
|
|
}
|
|
|
|
void getAnnouncements(int itgAwarenessID, int itgRowID) async {
|
|
try {
|
|
Utils.showLoading(context);
|
|
jsonResponse = await PendingTransactionsApiClient().getAnnouncements(itgAwarenessID, currentPageNo, itgRowID);
|
|
var jsonDecodedData = jsonDecode(jsonDecode(jsonResponse)['result']['data']);
|
|
for (int i = 0; i < jsonDecodedData.length; i++) {
|
|
getAnnouncementsObject.add(GetAnnouncementsObject.fromJson(jsonDecodedData[i]));
|
|
}
|
|
_foundAnnouncements = getAnnouncementsObject;
|
|
Utils.hideLoading(context);
|
|
setState(() {});
|
|
} catch (ex) {
|
|
Utils.hideLoading(context);
|
|
Utils.handleException(ex, context, null);
|
|
}
|
|
}
|
|
|
|
void openAnnouncementsDetails(int rowID) async {
|
|
await Navigator.pushNamed(context, AppRoutes.announcementsDetails, arguments: {"currentPageNo": currentPageNo, "rowID": rowID});
|
|
}
|
|
}
|