Inventory Management | Customer Management | Invoice Management Done | Commodity Rate Sync Done
This commit is contained in:
39
kifi-app/lib/core/widgets/barcode_scanner_screen.dart
Normal file
39
kifi-app/lib/core/widgets/barcode_scanner_screen.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mobile_scanner/mobile_scanner.dart';
|
||||
|
||||
class BarcodeScannerScreen extends StatefulWidget {
|
||||
const BarcodeScannerScreen({super.key});
|
||||
|
||||
@override
|
||||
State<BarcodeScannerScreen> createState() => _BarcodeScannerScreenState();
|
||||
}
|
||||
|
||||
class _BarcodeScannerScreenState extends State<BarcodeScannerScreen> {
|
||||
final MobileScannerController controller = MobileScannerController();
|
||||
bool _isScanned = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Scan Barcode')),
|
||||
body: MobileScanner(
|
||||
controller: controller,
|
||||
onDetect: (capture) {
|
||||
if (_isScanned) return;
|
||||
final List<Barcode> barcodes = capture.barcodes;
|
||||
if (barcodes.isNotEmpty && barcodes.first.rawValue != null) {
|
||||
_isScanned = true;
|
||||
final String code = barcodes.first.rawValue!;
|
||||
Navigator.pop(context, code);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
68
kifi-app/lib/core/widgets/premium_text_field.dart
Normal file
68
kifi-app/lib/core/widgets/premium_text_field.dart
Normal file
@@ -0,0 +1,68 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class PremiumTextField extends StatelessWidget {
|
||||
final String labelText;
|
||||
final TextEditingController? controller;
|
||||
final String? initialValue;
|
||||
final Widget? prefixIcon;
|
||||
final Widget? suffixIcon;
|
||||
final String? suffixText;
|
||||
final TextInputType? keyboardType;
|
||||
final TextCapitalization textCapitalization;
|
||||
final int maxLines;
|
||||
final bool obscureText;
|
||||
final String? Function(String?)? validator;
|
||||
final void Function(String)? onChanged;
|
||||
final void Function(String?)? onSaved;
|
||||
final bool darkTheme;
|
||||
|
||||
const PremiumTextField({
|
||||
super.key,
|
||||
required this.labelText,
|
||||
this.controller,
|
||||
this.initialValue,
|
||||
this.prefixIcon,
|
||||
this.suffixIcon,
|
||||
this.suffixText,
|
||||
this.keyboardType,
|
||||
this.textCapitalization = TextCapitalization.none,
|
||||
this.maxLines = 1,
|
||||
this.obscureText = false,
|
||||
this.validator,
|
||||
this.onChanged,
|
||||
this.onSaved,
|
||||
this.darkTheme = false,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TextFormField(
|
||||
controller: controller,
|
||||
initialValue: initialValue,
|
||||
decoration: InputDecoration(
|
||||
labelText: labelText,
|
||||
labelStyle: TextStyle(color: darkTheme ? Colors.white70 : Colors.grey[600]),
|
||||
prefixIcon: prefixIcon,
|
||||
suffixIcon: suffixIcon,
|
||||
suffixText: suffixText,
|
||||
suffixStyle: TextStyle(color: darkTheme ? Colors.white70 : Colors.grey),
|
||||
filled: true,
|
||||
fillColor: darkTheme ? Colors.black26 : Colors.grey[100],
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none),
|
||||
enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
borderSide: BorderSide(color: darkTheme ? Colors.white : Theme.of(context).colorScheme.primary, width: 2)
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
||||
),
|
||||
keyboardType: keyboardType,
|
||||
textCapitalization: textCapitalization,
|
||||
maxLines: maxLines,
|
||||
obscureText: obscureText,
|
||||
onChanged: onChanged,
|
||||
onSaved: onSaved,
|
||||
validator: validator,
|
||||
);
|
||||
}
|
||||
}
|
||||
220
kifi-app/lib/core/widgets/smart_search_dropdown.dart
Normal file
220
kifi-app/lib/core/widgets/smart_search_dropdown.dart
Normal file
@@ -0,0 +1,220 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SmartSearchDropdown<T> extends StatefulWidget {
|
||||
final List<T> items;
|
||||
final String Function(T) itemAsString;
|
||||
final void Function(T?) onChanged;
|
||||
final T? value;
|
||||
final String hintText;
|
||||
final Widget Function(BuildContext, T)? itemBuilder;
|
||||
final bool Function(T, String)? filterFn;
|
||||
|
||||
const SmartSearchDropdown({
|
||||
super.key,
|
||||
required this.items,
|
||||
required this.itemAsString,
|
||||
required this.onChanged,
|
||||
this.value,
|
||||
this.hintText = 'Type to search...',
|
||||
this.itemBuilder,
|
||||
this.filterFn,
|
||||
});
|
||||
|
||||
@override
|
||||
State<SmartSearchDropdown<T>> createState() => _SmartSearchDropdownState<T>();
|
||||
}
|
||||
|
||||
class _SmartSearchDropdownState<T> extends State<SmartSearchDropdown<T>> {
|
||||
final LayerLink _layerLink = LayerLink();
|
||||
final FocusNode _focusNode = FocusNode();
|
||||
final TextEditingController _controller = TextEditingController();
|
||||
OverlayEntry? _overlayEntry;
|
||||
bool _showAll = false;
|
||||
List<T> _filteredItems = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_filteredItems = widget.items;
|
||||
if (widget.value != null) {
|
||||
_controller.text = widget.itemAsString(widget.value as T);
|
||||
}
|
||||
_focusNode.addListener(() {
|
||||
if (_focusNode.hasFocus) {
|
||||
_showOverlay();
|
||||
} else {
|
||||
_removeOverlay();
|
||||
// Reset text to selected value if focus lost without selection
|
||||
if (widget.value != null) {
|
||||
_controller.text = widget.itemAsString(widget.value as T);
|
||||
} else {
|
||||
_controller.text = '';
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(SmartSearchDropdown<T> oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.items != oldWidget.items) {
|
||||
_filterItems(_controller.text);
|
||||
}
|
||||
if (widget.value != oldWidget.value) {
|
||||
if (widget.value != null) {
|
||||
_controller.text = widget.itemAsString(widget.value as T);
|
||||
} else {
|
||||
_controller.text = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_focusNode.dispose();
|
||||
_controller.dispose();
|
||||
_removeOverlay();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _filterItems(String query) {
|
||||
setState(() {
|
||||
if (query.isEmpty) {
|
||||
_filteredItems = widget.items;
|
||||
} else {
|
||||
_filteredItems = widget.items.where((item) {
|
||||
if (widget.filterFn != null) {
|
||||
return widget.filterFn!(item, query);
|
||||
}
|
||||
return widget.itemAsString(item).toLowerCase().contains(query.toLowerCase());
|
||||
}).toList();
|
||||
}
|
||||
});
|
||||
_overlayEntry?.markNeedsBuild();
|
||||
}
|
||||
|
||||
void _showOverlay() {
|
||||
_removeOverlay();
|
||||
_showAll = true;
|
||||
_filteredItems = widget.items;
|
||||
_overlayEntry = _createOverlayEntry();
|
||||
Overlay.of(context).insert(_overlayEntry!);
|
||||
}
|
||||
|
||||
void _removeOverlay() {
|
||||
_overlayEntry?.remove();
|
||||
_overlayEntry = null;
|
||||
}
|
||||
|
||||
OverlayEntry _createOverlayEntry() {
|
||||
RenderBox renderBox = context.findRenderObject() as RenderBox;
|
||||
var size = renderBox.size;
|
||||
|
||||
return OverlayEntry(
|
||||
builder: (context) => Positioned(
|
||||
width: size.width,
|
||||
child: CompositedTransformFollower(
|
||||
link: _layerLink,
|
||||
showWhenUnlinked: false,
|
||||
offset: Offset(0.0, size.height + 5.0),
|
||||
child: Material(
|
||||
elevation: 4.0,
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
color: Theme.of(context).cardColor,
|
||||
child: StatefulBuilder(
|
||||
builder: (context, setOverlayState) {
|
||||
final displayItems = _showAll ? _filteredItems : (_filteredItems.isNotEmpty ? [_filteredItems.first] : <T>[]);
|
||||
|
||||
return Container(
|
||||
constraints: const BoxConstraints(maxHeight: 250),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (displayItems.isEmpty)
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
child: Text('No matches found'),
|
||||
)
|
||||
else
|
||||
Flexible(
|
||||
child: ListView.builder(
|
||||
shrinkWrap: true,
|
||||
padding: EdgeInsets.zero,
|
||||
itemCount: displayItems.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = displayItems[index];
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
widget.onChanged(item);
|
||||
_controller.text = widget.itemAsString(item);
|
||||
_focusNode.unfocus();
|
||||
},
|
||||
child: widget.itemBuilder != null
|
||||
? widget.itemBuilder!(context, item)
|
||||
: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12.0),
|
||||
child: Text(widget.itemAsString(item)),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
if (!_showAll && _controller.text.isEmpty && widget.items.length > 1)
|
||||
InkWell(
|
||||
onTap: () {
|
||||
setOverlayState(() {
|
||||
_showAll = true;
|
||||
});
|
||||
},
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(top: BorderSide(color: Colors.grey.withOpacity(0.2))),
|
||||
),
|
||||
child: const Text(
|
||||
'Show all',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Colors.blue, fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CompositedTransformTarget(
|
||||
link: _layerLink,
|
||||
child: TextFormField(
|
||||
controller: _controller,
|
||||
focusNode: _focusNode,
|
||||
decoration: InputDecoration(
|
||||
hintText: widget.hintText,
|
||||
suffixIcon: const Icon(Icons.arrow_drop_down, color: Colors.grey),
|
||||
filled: Theme.of(context).inputDecorationTheme.filled ?? true,
|
||||
fillColor: Theme.of(context).inputDecorationTheme.fillColor ?? Colors.grey[100],
|
||||
border: Theme.of(context).inputDecorationTheme.border ?? OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none),
|
||||
enabledBorder: Theme.of(context).inputDecorationTheme.enabledBorder ?? OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none),
|
||||
focusedBorder: Theme.of(context).inputDecorationTheme.focusedBorder ?? OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
borderSide: BorderSide(color: Theme.of(context).colorScheme.primary, width: 2)
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
||||
),
|
||||
onChanged: (val) {
|
||||
_showAll = true; // when user types, we want to show all matching results
|
||||
_filterItems(val);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user