Initial commit: Penyerahan final Source code Tugas Akhir
This commit is contained in:
29
lib/screens/checkout/components/cardmonth.dart
Normal file
29
lib/screens/checkout/components/cardmonth.dart
Normal file
@ -0,0 +1,29 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class CardMonthInputFormatter extends TextInputFormatter {
|
||||
@override
|
||||
TextEditingValue formatEditUpdate(
|
||||
TextEditingValue oldValue, TextEditingValue newValue) {
|
||||
var masaController = newValue.text;
|
||||
if (newValue.selection.baseOffset == 0) {
|
||||
return newValue;
|
||||
}
|
||||
|
||||
var buffer = new StringBuffer();
|
||||
|
||||
for (int i = 0; i < masaController.length; i++) {
|
||||
buffer.write(masaController[i]);
|
||||
var nonZeroIndex = i + 1;
|
||||
|
||||
if (nonZeroIndex % 2 == 0 && nonZeroIndex != masaController.length) {
|
||||
buffer.write('/');
|
||||
}
|
||||
}
|
||||
|
||||
var string = buffer.toString();
|
||||
return newValue.copyWith(
|
||||
text: string,
|
||||
selection: new TextSelection.collapsed(offset: string.length));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user