add pagination for pages
This commit is contained in:
@@ -15,6 +15,7 @@ import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:share/share.dart';
|
||||
|
||||
import '../../pagination/paginator_listview.dart';
|
||||
import 'invitation_create.dart';
|
||||
|
||||
class CustomerList extends StatefulWidget {
|
||||
@@ -27,6 +28,13 @@ class _CustomerListState extends State<CustomerList> {
|
||||
final double dotSize = 15.0;
|
||||
bool _isLoading = false;
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
context.read<CustomerModel>().loadPaginationCustomers();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var customerModel = Provider.of<CustomerModel>(context);
|
||||
@@ -34,55 +42,40 @@ class _CustomerListState extends State<CustomerList> {
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
leading: new IconButton(
|
||||
icon: new Icon(CupertinoIcons.back),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
actions: <Widget>[
|
||||
IconButton(
|
||||
icon: Icon(Icons.search, color: Colors.white),
|
||||
onPressed: () => searchUser(context, onUserSelect: (u) {
|
||||
_select(u);
|
||||
})),
|
||||
],
|
||||
backgroundColor: primaryColor,
|
||||
title: LocalText(
|
||||
context,
|
||||
"customer.list.title",
|
||||
fontSize: 20,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
CupertinoPageRoute(builder: (context) => InvitationCreate()));
|
||||
},
|
||||
icon: Icon(Icons.add),
|
||||
label: LocalText(context, "invitation.new", color: Colors.white),
|
||||
backgroundColor: primaryColor,
|
||||
),
|
||||
body: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Expanded(
|
||||
child: ListView.separated(
|
||||
separatorBuilder: (context, index) => Divider(
|
||||
color: Colors.grey,
|
||||
),
|
||||
scrollDirection: Axis.vertical,
|
||||
shrinkWrap: true,
|
||||
itemCount: customerModel.customers.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
User customer = customerModel.customers[index];
|
||||
return _item(customer);
|
||||
}),
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
leading: new IconButton(
|
||||
icon: new Icon(CupertinoIcons.back),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
IconButton(
|
||||
icon: Icon(Icons.search, color: Colors.white),
|
||||
onPressed: () => searchUser(context, onUserSelect: (u) {
|
||||
_select(u);
|
||||
})),
|
||||
],
|
||||
backgroundColor: primaryColor,
|
||||
title: LocalText(
|
||||
context,
|
||||
"customer.list.title",
|
||||
fontSize: 20,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
CupertinoPageRoute(builder: (context) => InvitationCreate()));
|
||||
},
|
||||
icon: Icon(Icons.add),
|
||||
label: LocalText(context, "invitation.new", color: Colors.white),
|
||||
backgroundColor: primaryColor,
|
||||
),
|
||||
body: PaginatorListView<User>(
|
||||
paginatorListener: customerModel.getCustomers!,
|
||||
rowBuilder: (p) => _item(p),
|
||||
color: primaryColor)),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
import 'package:fcs/domain/entities/user.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/customer/model/customer_model.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/widgets/display_text.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
typedef void FindCallBack();
|
||||
|
||||
class InvitationEditor extends StatefulWidget {
|
||||
final User? customer;
|
||||
const InvitationEditor({this.customer});
|
||||
@override
|
||||
_InvitationEditorState createState() => _InvitationEditorState();
|
||||
}
|
||||
|
||||
class _InvitationEditorState extends State<InvitationEditor> {
|
||||
bool _isLoading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var phoneNumberBox = Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: DisplayText(
|
||||
text: widget.customer!.phoneNumber,
|
||||
labelTextKey: getLocalString(context, "customer.phone"),
|
||||
iconData: Icons.phone,
|
||||
)),
|
||||
IconButton(
|
||||
icon: Icon(Icons.open_in_new, color: primaryColor),
|
||||
onPressed: () => call(context, widget.customer?.phoneNumber ?? "")),
|
||||
],
|
||||
);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
shadowColor: Colors.transparent,
|
||||
centerTitle: true,
|
||||
leading: new IconButton(
|
||||
icon: new Icon(
|
||||
CupertinoIcons.back,
|
||||
color: primaryColor,
|
||||
size: 30,
|
||||
),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
title: Text(
|
||||
widget.customer?.name ?? "",
|
||||
style: TextStyle(fontSize: 20, color: primaryColor),
|
||||
),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: [phoneNumberBox],
|
||||
),
|
||||
),
|
||||
fcsButton(context, getLocalString(context, "btn.delete"),
|
||||
callack: _delete)
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
_delete() async {
|
||||
showConfirmDialog(context, "invitation.confirm.delete", () async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
if (widget.customer == null) return;
|
||||
CustomerModel customerModel =
|
||||
Provider.of<CustomerModel>(context, listen: false);
|
||||
try {
|
||||
await customerModel.deleteInvite(widget.customer?.phoneNumber ?? "");
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -13,89 +13,28 @@ class CustomerModel extends BaseModel {
|
||||
final log = Logger('CustomerModel');
|
||||
PaginatorListener<User>? getCustomers;
|
||||
|
||||
List<User> customers = [];
|
||||
List<User> invitations = [];
|
||||
StreamSubscription<QuerySnapshot>? customerListener;
|
||||
StreamSubscription<QuerySnapshot>? invitationListener;
|
||||
|
||||
@override
|
||||
void privilegeChanged() {
|
||||
super.privilegeChanged();
|
||||
_loadCustomer();
|
||||
_loadInvitations();
|
||||
}
|
||||
|
||||
@override
|
||||
logout() async {
|
||||
if (customerListener != null) customerListener!.cancel();
|
||||
if (invitationListener != null) invitationListener!.cancel();
|
||||
customers = [];
|
||||
invitations = [];
|
||||
getCustomers?.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Future<void> inviteUser(String userName, String phoneNumber) {
|
||||
return Services.instance.userService.inviteUser(userName, phoneNumber);
|
||||
}
|
||||
|
||||
Future<void> deleteInvite(String phoneNumber) {
|
||||
return Services.instance.userService.deleteInvite(phoneNumber);
|
||||
}
|
||||
|
||||
Future<void> acceptRequest(String userID) {
|
||||
return Services.instance.userService.acceptRequest(userID);
|
||||
}
|
||||
|
||||
Future<void> _loadCustomer() async {
|
||||
loadPaginationCustomers() {
|
||||
if (user == null && !user!.hasCustomers()) return;
|
||||
|
||||
try {
|
||||
if (customerListener != null) customerListener!.cancel();
|
||||
String path = "/$user_collection";
|
||||
Query col = FirebaseFirestore.instance
|
||||
.collection(path)
|
||||
.where("is_sys_admin", isEqualTo: false);
|
||||
|
||||
customerListener = FirebaseFirestore.instance
|
||||
.collection("/$user_collection")
|
||||
.where("is_sys_admin", isEqualTo: false)
|
||||
.orderBy("message_time", descending: true)
|
||||
.snapshots()
|
||||
.listen((QuerySnapshot snapshot) {
|
||||
customers.clear();
|
||||
customers = snapshot.docs.map((documentSnapshot) {
|
||||
var user = User.fromMap(
|
||||
documentSnapshot.data() as Map<String, dynamic>,
|
||||
documentSnapshot.id);
|
||||
return user;
|
||||
}).toList();
|
||||
notifyListeners();
|
||||
});
|
||||
} catch (e) {
|
||||
log.warning("error:$e");
|
||||
}
|
||||
}
|
||||
Query pageQuery = FirebaseFirestore.instance
|
||||
.collection(path)
|
||||
.where("is_sys_admin", isEqualTo: false)
|
||||
.orderBy("message_time", descending: true);
|
||||
|
||||
Future<void> _loadInvitations() async {
|
||||
if (user == null && !user!.hasCustomers()) return;
|
||||
|
||||
try {
|
||||
if (invitationListener != null) invitationListener!.cancel();
|
||||
|
||||
invitationListener = FirebaseFirestore.instance
|
||||
.collection("/$invitations_collection")
|
||||
.snapshots()
|
||||
.listen((QuerySnapshot snapshot) {
|
||||
invitations.clear();
|
||||
invitations = snapshot.docs.map((documentSnapshot) {
|
||||
var user = User.fromMap(
|
||||
documentSnapshot.data() as Map<String, dynamic>,
|
||||
documentSnapshot.id);
|
||||
return user;
|
||||
}).toList();
|
||||
notifyListeners();
|
||||
});
|
||||
} catch (e) {
|
||||
log.warning("error:$e");
|
||||
}
|
||||
getCustomers?.close();
|
||||
getCustomers = PaginatorListener<User>(
|
||||
col, pageQuery, (data, id) => User.fromMap(data, id),
|
||||
rowPerLoad: 30);
|
||||
}
|
||||
|
||||
Future<User> getUser(String? id) async {
|
||||
@@ -125,4 +64,16 @@ class CustomerModel extends BaseModel {
|
||||
Future<void> enableUser(User user, bool enabled) {
|
||||
return Services.instance.userService.enableUser(user.id ?? "", enabled);
|
||||
}
|
||||
|
||||
Future<void> inviteUser(String userName, String phoneNumber) {
|
||||
return Services.instance.userService.inviteUser(userName, phoneNumber);
|
||||
}
|
||||
|
||||
Future<void> deleteInvite(String phoneNumber) {
|
||||
return Services.instance.userService.deleteInvite(phoneNumber);
|
||||
}
|
||||
|
||||
Future<void> acceptRequest(String userID) {
|
||||
return Services.instance.userService.acceptRequest(userID);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user