chore: initial commit Dutra Store POS app
This commit is contained in:
26
lib/utils/colors.dart
Normal file
26
lib/utils/colors.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
const kBackground = Color(0xFF0B1220);
|
||||
const kSurface = Color(0xFF141C2E);
|
||||
const kSurface2 = Color(0xFF1C2638);
|
||||
const kBorder = Color(0xFF2A3650);
|
||||
const kText = Color(0xFFE8EEF7);
|
||||
const kMuted = Color(0xFF93A1B8);
|
||||
const kAccent = Color(0xFFF59E0B);
|
||||
const kSuccess = Color(0xFF22C55E);
|
||||
const kDanger = Color(0xFFEF4444);
|
||||
|
||||
const kRadius = 18.0;
|
||||
|
||||
const List<Color> productPalette = [
|
||||
Color(0xFFF59E0B),
|
||||
Color(0xFF22C55E),
|
||||
Color(0xFF3B82F6),
|
||||
Color(0xFFEC4899),
|
||||
];
|
||||
|
||||
Color productAccent(String name) {
|
||||
if (name.isEmpty) return productPalette.first;
|
||||
final index = name.hashCode.abs() % productPalette.length;
|
||||
return productPalette[index];
|
||||
}
|
||||
26
lib/utils/format.dart
Normal file
26
lib/utils/format.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
String formatRupiah(double number) {
|
||||
final rounded = number.round();
|
||||
final formatted = rounded
|
||||
.toString()
|
||||
.replaceAllMapped(RegExp(r'\B(?=(\d{3})+(?!\d))'), (m) => '.');
|
||||
return 'Rp $formatted';
|
||||
}
|
||||
|
||||
String formatTanggal(DateTime date) {
|
||||
const bulan = [
|
||||
'Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun',
|
||||
'Jul', 'Agu', 'Sep', 'Okt', 'Nov', 'Des'
|
||||
];
|
||||
return '${date.day} ${bulan[date.month - 1]} ${date.year}';
|
||||
}
|
||||
|
||||
String formatWaktu(DateTime date) {
|
||||
final j = date.hour.toString().padLeft(2, '0');
|
||||
final m = date.minute.toString().padLeft(2, '0');
|
||||
return '$j:$m';
|
||||
}
|
||||
|
||||
String uid() {
|
||||
return DateTime.now().microsecondsSinceEpoch.toRadixString(36) +
|
||||
(DateTime.now().millisecond).toRadixString(36);
|
||||
}
|
||||
60
lib/utils/rupiah_input.dart
Normal file
60
lib/utils/rupiah_input.dart
Normal file
@@ -0,0 +1,60 @@
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class RupiahInputFormatter extends TextInputFormatter {
|
||||
@override
|
||||
TextEditingValue formatEditUpdate(
|
||||
TextEditingValue oldValue, TextEditingValue newValue) {
|
||||
if (newValue.text.isEmpty) {
|
||||
return newValue;
|
||||
}
|
||||
|
||||
final digits = newValue.text.replaceAll(RegExp(r'[^0-9]'), '');
|
||||
if (digits.isEmpty) {
|
||||
return const TextEditingValue(text: '');
|
||||
}
|
||||
|
||||
final formatted = _formatRupiah(digits);
|
||||
|
||||
int newOffset = formatted.length;
|
||||
if (oldValue.text.isNotEmpty) {
|
||||
final oldLength = oldValue.text.replaceAll(RegExp(r'[^0-9]'), '').length;
|
||||
final newLength = digits.length;
|
||||
final oldCursor = oldValue.selection.baseOffset;
|
||||
|
||||
if (newLength < oldLength) {
|
||||
final digitsBeforeCursor = oldValue.text.substring(0, oldCursor).replaceAll(RegExp(r'[^0-9]'), '').length;
|
||||
newOffset = (digitsBeforeCursor).clamp(0, formatted.length);
|
||||
} else if (oldCursor < oldValue.text.length) {
|
||||
final digitsBeforeCursor = oldValue.text.substring(0, oldCursor).replaceAll(RegExp(r'[^0-9]'), '').length;
|
||||
newOffset = (digitsBeforeCursor).clamp(0, formatted.length);
|
||||
}
|
||||
}
|
||||
|
||||
return TextEditingValue(
|
||||
text: formatted,
|
||||
selection: TextSelection.collapsed(offset: newOffset),
|
||||
);
|
||||
}
|
||||
|
||||
String _formatRupiah(String digits) {
|
||||
final buffer = StringBuffer();
|
||||
final len = digits.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (i > 0 && (len - i) % 3 == 0) {
|
||||
buffer.write('.');
|
||||
}
|
||||
buffer.write(digits[i]);
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
static String formatNumber(int number) {
|
||||
return RupiahInputFormatter()._formatRupiah(number.toString());
|
||||
}
|
||||
|
||||
static int? getRawValue(String formattedText) {
|
||||
final digits = formattedText.replaceAll(RegExp(r'[^0-9]'), '');
|
||||
if (digits.isEmpty) return null;
|
||||
return int.tryParse(digits);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user