doubletosinhala 0.0.1
doubletosinhala: ^0.0.1 copied to clipboard
A Flutter and Dart library to convert double and numeric values into Sinhala words, supporting currency format, decimals, and large numbers.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:doubletosinhala/doubletosinhala.dart';
void main() {
runApp(const DoubleToSinhalaExampleApp());
}
class DoubleToSinhalaExampleApp extends StatelessWidget {
const DoubleToSinhalaExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Double to Sinhala Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const ConversionHomePage(),
);
}
}
class ConversionHomePage extends StatefulWidget {
const ConversionHomePage({super.key});
@override
State<ConversionHomePage> createState() => _ConversionHomePageState();
}
class _ConversionHomePageState extends State<ConversionHomePage> {
final TextEditingController _controller =
TextEditingController(text: '1250.75');
double _currentValue = 1250.75;
bool _includeRupeesPrefix = true;
bool _appendOnly = true;
@override
void initState() {
super.initState();
_controller.addListener(_onTextChanged);
}
@override
void dispose() {
_controller.removeListener(_onTextChanged);
_controller.dispose();
super.dispose();
}
void _onTextChanged() {
final parsed = double.tryParse(_controller.text.trim());
setState(() {
_currentValue = parsed ?? 0.0;
});
}
@override
Widget build(BuildContext context) {
final standardWords = _currentValue.toSinhalaWords();
final currencyWords = _currentValue.toSinhalaCurrency(
appendOnly: _appendOnly,
includeRupeesPrefix: _includeRupeesPrefix,
);
final decimalWords =
_currentValue.toSinhalaWords(format: SinhalaFormat.decimal);
return Scaffold(
appBar: AppBar(
title: const Text('Double to Sinhala Converter'),
elevation: 2,
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Card(
elevation: 0,
color: Theme.of(context).colorScheme.surfaceContainerHighest,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Input Numeric / Double Value',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 12),
TextField(
controller: _controller,
keyboardType:
const TextInputType.numberWithOptions(decimal: true),
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Enter number (e.g. 1250.75)',
prefixIcon: Icon(Icons.calculate),
),
),
const SizedBox(height: 12),
Wrap(
spacing: 8,
children: [
ActionChip(
label: const Text('100.00'),
onPressed: () => _controller.text = '100.00',
),
ActionChip(
label: const Text('1234.50'),
onPressed: () => _controller.text = '1234.50',
),
ActionChip(
label: const Text('50000.25'),
onPressed: () => _controller.text = '50000.25',
),
ActionChip(
label: const Text('1000000'),
onPressed: () => _controller.text = '1000000',
),
],
),
],
),
),
),
const SizedBox(height: 20),
_buildResultCard(
context,
title: 'Standard Words (සාමාන්ය වචන)',
content: standardWords,
icon: Icons.text_fields,
),
const SizedBox(height: 16),
_buildResultCard(
context,
title: 'Sri Lankan Currency (රුපියල් සහ ශත)',
content: currencyWords,
icon: Icons.payments,
extraControls: Row(
children: [
FilterChip(
label: const Text('"රුපියල්" Prefix'),
selected: _includeRupeesPrefix,
onSelected: (val) =>
setState(() => _includeRupeesPrefix = val),
),
const SizedBox(width: 8),
FilterChip(
label: const Text('"පමණි" Suffix'),
selected: _appendOnly,
onSelected: (val) => setState(() => _appendOnly = val),
),
],
),
),
const SizedBox(height: 16),
_buildResultCard(
context,
title: 'Decimal Reading (දශම කියවීම)',
content: decimalWords,
icon: Icons.numbers,
),
],
),
),
);
}
Widget _buildResultCard(
BuildContext context, {
required String title,
required String content,
required IconData icon,
Widget? extraControls,
}) {
return Card(
elevation: 2,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(icon, color: Theme.of(context).colorScheme.primary),
const SizedBox(width: 8),
Expanded(
child: Text(
title,
style: Theme.of(context).textTheme.titleSmall?.copyWith(
fontWeight: FontWeight.bold,
),
),
),
IconButton(
icon: const Icon(Icons.copy, size: 18),
tooltip: 'Copy',
onPressed: () {
Clipboard.setData(ClipboardData(text: content));
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Copied to clipboard!'),
duration: Duration(seconds: 1),
),
);
},
),
],
),
if (extraControls != null) ...[
const SizedBox(height: 8),
extraControls,
],
const Divider(),
SelectableText(
content,
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
fontSize: 18,
fontWeight: FontWeight.w500,
color: Theme.of(context).colorScheme.onSurface,
),
),
],
),
),
);
}
}