|
|
|
|
@ -10,77 +10,83 @@ import 'package:test_sa/new_views/app_style/app_color.dart';
|
|
|
|
|
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
|
|
|
|
|
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/date_and_time/date_picker.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/loaders/lazy_loading.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/loaders/no_item_found.dart';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import 'models/swipe_transaction_history.dart';
|
|
|
|
|
|
|
|
|
|
class SwipeHistoryView extends StatefulWidget {
|
|
|
|
|
static const routeName = '/swipe_list_view';
|
|
|
|
|
bool showAppBar = true;
|
|
|
|
|
|
|
|
|
|
const SwipeHistoryView({Key key}) : super(key: key);
|
|
|
|
|
SwipeHistoryView({Key key, this.showAppBar = true}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<SwipeHistoryView> createState() => _SwipeHistoryViewState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _SwipeHistoryViewState extends State<SwipeHistoryView> {
|
|
|
|
|
DateTime dateFrom = DateTime.now();
|
|
|
|
|
DateTime dateTo = DateTime.now();
|
|
|
|
|
UserProvider _userProvider;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
getSwipeHistory();
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void getSwipeHistory () {
|
|
|
|
|
_userProvider = Provider.of<UserProvider>(context,listen:false);
|
|
|
|
|
void getSwipeHistory() {
|
|
|
|
|
_userProvider = Provider.of<UserProvider>(context, listen: false);
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
|
|
|
|
await _userProvider.getSwipeTransactionHistory(userId: _userProvider.user.userID,dateFrom: dateFrom,dateTo: dateTo);
|
|
|
|
|
await _userProvider.getSwipeTransactionHistory(userId: _userProvider.user.userID, dateFrom: dateFrom, dateTo: dateTo);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: const DefaultAppBar(title: 'Swipe History',),
|
|
|
|
|
body: Column(
|
|
|
|
|
crossAxisAlignment:CrossAxisAlignment.start,
|
|
|
|
|
appBar: widget.showAppBar ? const DefaultAppBar(title: 'Swipe History') : null,
|
|
|
|
|
body: SingleChildScrollView(
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
|
|
8.height,
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
ADatePicker(
|
|
|
|
|
label: context.translation.from,
|
|
|
|
|
showDateOnly: true,
|
|
|
|
|
date: dateFrom,
|
|
|
|
|
from: DateTime(DateTime.now().year - 5, DateTime.now().month, DateTime.now().day),
|
|
|
|
|
formatDateWithTime: true,
|
|
|
|
|
formatDateWithTime: false,
|
|
|
|
|
onDatePicker: (selectedDate) {
|
|
|
|
|
if (selectedDate != null) {
|
|
|
|
|
showTimePicker(
|
|
|
|
|
context: context,
|
|
|
|
|
initialTime: TimeOfDay.now(),
|
|
|
|
|
).then((selectedTime) {
|
|
|
|
|
// Handle the selected date and time here.
|
|
|
|
|
if (selectedTime != null) {
|
|
|
|
|
DateTime selectedDateTime = DateTime(
|
|
|
|
|
selectedDate.year,
|
|
|
|
|
selectedDate.month,
|
|
|
|
|
selectedDate.day,
|
|
|
|
|
selectedTime.hour,
|
|
|
|
|
selectedTime.minute,
|
|
|
|
|
);
|
|
|
|
|
if (selectedDateTime != null) {
|
|
|
|
|
setState(() {
|
|
|
|
|
dateFrom = selectedDateTime;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
dateFrom = selectedDate;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if (selectedDate != null) {
|
|
|
|
|
// showTimePicker(
|
|
|
|
|
// context: context,
|
|
|
|
|
// initialTime: TimeOfDay.now(),
|
|
|
|
|
// ).then((selectedTime) {
|
|
|
|
|
// // Handle the selected date and time here.
|
|
|
|
|
// if (selectedTime != null) {
|
|
|
|
|
// DateTime selectedDateTime = DateTime(
|
|
|
|
|
// selectedDate.year,
|
|
|
|
|
// selectedDate.month,
|
|
|
|
|
// selectedDate.day,
|
|
|
|
|
// selectedTime.hour,
|
|
|
|
|
// selectedTime.minute,
|
|
|
|
|
// );
|
|
|
|
|
// if (selectedDateTime != null) {
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
},
|
|
|
|
|
).expanded,
|
|
|
|
|
8.width,
|
|
|
|
|
@ -88,58 +94,55 @@ class _SwipeHistoryViewState extends State<SwipeHistoryView> {
|
|
|
|
|
label: context.translation.to,
|
|
|
|
|
date: dateTo,
|
|
|
|
|
from: DateTime(DateTime.now().year - 5, DateTime.now().month, DateTime.now().day),
|
|
|
|
|
formatDateWithTime: true,
|
|
|
|
|
formatDateWithTime: false,
|
|
|
|
|
onDatePicker: (selectedDate) {
|
|
|
|
|
if (selectedDate != null) {
|
|
|
|
|
showTimePicker(
|
|
|
|
|
context: context,
|
|
|
|
|
initialTime: TimeOfDay.now(),
|
|
|
|
|
).then((selectedTime) {
|
|
|
|
|
// Handle the selected date and time here.
|
|
|
|
|
if (selectedTime != null) {
|
|
|
|
|
DateTime selectedDateTime = DateTime(
|
|
|
|
|
selectedDate.year,
|
|
|
|
|
selectedDate.month,
|
|
|
|
|
selectedDate.day,
|
|
|
|
|
selectedTime.hour,
|
|
|
|
|
selectedTime.minute,
|
|
|
|
|
);
|
|
|
|
|
if (selectedDateTime != null) {
|
|
|
|
|
setState(() {
|
|
|
|
|
dateTo = selectedDateTime;
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
dateTo = selectedDate;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// if (selectedDate != null) {
|
|
|
|
|
// showTimePicker(
|
|
|
|
|
// context: context,
|
|
|
|
|
// initialTime: TimeOfDay.now(),
|
|
|
|
|
// ).then((selectedTime) {
|
|
|
|
|
// // Handle the selected date and time here.
|
|
|
|
|
// if (selectedTime != null) {
|
|
|
|
|
// DateTime selectedDateTime = DateTime(
|
|
|
|
|
// selectedDate.year,
|
|
|
|
|
// selectedDate.month,
|
|
|
|
|
// selectedDate.day,
|
|
|
|
|
// selectedTime.hour,
|
|
|
|
|
// selectedTime.minute,
|
|
|
|
|
// );
|
|
|
|
|
// if (selectedDateTime != null) {
|
|
|
|
|
// setState(() {
|
|
|
|
|
// dateTo = selectedDateTime;
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
},
|
|
|
|
|
).expanded,
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
12.height,
|
|
|
|
|
|
|
|
|
|
AppFilledButton(label: context.translation.search, maxWidth: false, onPressed: getSwipeHistory),
|
|
|
|
|
8.height,
|
|
|
|
|
Divider(thickness: 2,),
|
|
|
|
|
|
|
|
|
|
Consumer<UserProvider>(
|
|
|
|
|
builder: (context, snapshot,child) {
|
|
|
|
|
return SwipeHistoryList(snapshot.swipeHistory ?? [], snapshot.isLoading).expanded;
|
|
|
|
|
}
|
|
|
|
|
const Divider(
|
|
|
|
|
thickness: 2,
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Consumer<UserProvider>(builder: (context, snapshot, child) {
|
|
|
|
|
return SwipeHistoryList(snapshot.swipeHistory ?? [], snapshot.isLoading);
|
|
|
|
|
}),
|
|
|
|
|
],
|
|
|
|
|
).paddingAll(20),
|
|
|
|
|
).paddingOnly(start: 20, end: 20, bottom: 20),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SwipeHistoryList extends StatelessWidget {
|
|
|
|
|
List<SwipeHistory> list;
|
|
|
|
|
bool isLoading;
|
|
|
|
|
@ -149,21 +152,29 @@ class SwipeHistoryList extends StatelessWidget {
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return (list.isEmpty && !isLoading)
|
|
|
|
|
? NoItemFound(message: context.translation.noDataFound)
|
|
|
|
|
? context.translation.noDataFound.heading5(context).custom(color: context.isDark ? AppColor.neutral10 : AppColor.neutral50).center
|
|
|
|
|
: ListView.separated(
|
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
padding: EdgeInsets.only(top: 12.toScreenHeight),
|
|
|
|
|
itemBuilder: (cxt, index) {
|
|
|
|
|
if (isLoading) return const SizedBox().toRequestShimmer(cxt, isLoading);
|
|
|
|
|
if (isLoading)
|
|
|
|
|
return const SizedBox(
|
|
|
|
|
height: 20,
|
|
|
|
|
).toRequestShimmer(cxt, isLoading);
|
|
|
|
|
return SwipeHistoryCard(list[index]);
|
|
|
|
|
},
|
|
|
|
|
separatorBuilder: (cxt, index) => 12.height,
|
|
|
|
|
itemCount: isLoading ? 6 : list.length);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class SwipeHistoryCard extends StatelessWidget {
|
|
|
|
|
final SwipeHistory swipeHistory;
|
|
|
|
|
final bool showShadow;
|
|
|
|
|
|
|
|
|
|
const SwipeHistoryCard(this.swipeHistory, {Key key, this.showShadow = true}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Column(
|
|
|
|
|
@ -173,7 +184,8 @@ class SwipeHistoryCard extends StatelessWidget {
|
|
|
|
|
Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(swipeHistory.swipeTime.toServiceRequestDetailsFormat, textAlign: TextAlign.end, style: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral50)),
|
|
|
|
|
Text(swipeHistory.swipeTime.toServiceRequestDetailsFormat,
|
|
|
|
|
textAlign: TextAlign.end, style: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral50)),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
8.height,
|
|
|
|
|
@ -186,4 +198,3 @@ class SwipeHistoryCard extends StatelessWidget {
|
|
|
|
|
).toShadowContainer(context, showShadow: showShadow);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|