update discount

This commit is contained in:
tzw
2021-09-13 11:20:35 +06:30
parent 6155df4d50
commit 062946d2e1
3 changed files with 15 additions and 18 deletions

View File

@@ -85,7 +85,8 @@ class _InvitationCreateState extends State<InvitationCreate> {
),
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey.shade400, width: 1),
border:
Border.all(color: Colors.grey.shade400, width: 1),
borderRadius: BorderRadius.all(Radius.circular(12.0))),
child: CountryCodePicker(
onChanged: _countryChange,
@@ -94,9 +95,7 @@ class _InvitationCreateState extends State<InvitationCreate> {
showCountryOnly: false,
showOnlyCountryWhenClosed: false,
alignLeft: false,
textStyle: TextStyle(
fontSize: 16,
),
textStyle: TextStyle(fontSize: 16, color: Colors.black87),
),
),
SizedBox(

View File

@@ -14,10 +14,11 @@ class DiscountModel extends BaseModel {
StreamSubscription<QuerySnapshot>? listener;
List<Discount> _discounts = [];
List<Discount> get discounts =>
_selectedIndex == 1 ? _discounts : List<Discount>.from(_used.values);
List<Discount> get discounts => _selectedIndex == 1
? _discounts
: List<Discount>.from(_used?.values ?? []);
late Paginator _used;
Paginator? _used;
bool isLoading = false;
int _selectedIndex = 1;
set selectedIndex(int index) {
@@ -31,7 +32,7 @@ class DiscountModel extends BaseModel {
_selectedIndex = 1;
_load();
if (_getUsed() != null) _used = _getUsed();
_used.load();
_used?.load();
}
void initUser(user) {
@@ -49,8 +50,7 @@ class DiscountModel extends BaseModel {
.listen((snaps) {
_discounts.clear();
snaps.docs.forEach((d) {
_discounts
.add(Discount.fromMap(d.data() as Map<String, dynamic>, d.id));
_discounts.add(Discount.fromMap(d.data(), d.id));
});
notifyListeners();
});
@@ -94,10 +94,10 @@ class DiscountModel extends BaseModel {
}
Future<void> loadMore() async {
if (_used.ended || _selectedIndex == 1) return;
if (_used!.ended || _selectedIndex == 1) return;
isLoading = true;
notifyListeners();
await _used.load(onFinished: () {
await _used!.load(onFinished: () {
isLoading = false;
notifyListeners();
});
@@ -105,7 +105,7 @@ class DiscountModel extends BaseModel {
Future<void> refresh() async {
if (_selectedIndex == 1) return;
await _used.refresh(onFinished: () {
await _used!.refresh(onFinished: () {
notifyListeners();
});
}
@@ -113,7 +113,7 @@ class DiscountModel extends BaseModel {
@override
logout() async {
if (listener != null) await listener!.cancel();
if (_used != null) _used.close();
if (_used != null) _used!.close();
_discounts = [];
}

View File

@@ -90,9 +90,7 @@ class _SigninPageState extends State<SigninPage> {
showCountryOnly: false,
showOnlyCountryWhenClosed: false,
alignLeft: false,
textStyle: TextStyle(
fontSize: 16,
),
textStyle: TextStyle(fontSize: 16, color: Colors.black87),
),
),
SizedBox(