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