dart_unit_converter 0.0.2 dart_unit_converter: ^0.0.2 copied to clipboard
A data unit converter package.
// ignore_for_file: avoid_print
import 'package:dart_unit_converter/dart_unit_converter.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Example Data Converter Apps',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
final converter = DataConverter();
final dataInputController = TextEditingController();
final dataValueController = TextEditingController();
final timeInputController = TextEditingController();
final timeValueController = TextEditingController();
/// EXAMPLE OF TIME CONVERTER -- [parsedValue]
void useConverterFromByte() {
final parsedValue = int.parse(dataInputController.text);
dataValueController.text = parsedValue.convertDataToString();
}
void useConverterFromSeconds() {
final parsedValue = timeInputController.text;
timeValueController.text = parsedValue.timeDifferent();
}
@override
void initState() {
super.initState();
timeInputController.text = '2022-08-22 20:18:04Z';
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Example Apps'),
),
body: Padding(
padding: const EdgeInsets.all(18.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
byteToStringSection(),
const Padding(
padding: EdgeInsets.symmetric(vertical: 40),
child: Divider(),
),
timeConvertSection(),
],
),
),
);
}
// TIME CONVERT EXAMPLE
Widget timeConvertSection() {
return Column(
children: [
const SizedBox(height: 24),
const Text(
'From DateTime Pared to Customable String',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16,
),
),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: 2,
child: TextFormField(
controller: timeInputController,
keyboardType: TextInputType.number,
),
),
],
),
const Padding(
padding: EdgeInsets.fromLTRB(10, 20, 10, 0),
child: Text('is'),
),
TextFormField(
controller: timeValueController,
keyboardType: TextInputType.number,
textAlign: TextAlign.center,
enabled: false,
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: useConverterFromSeconds,
child: const Text('Convert'),
),
],
);
}
/// DATA CONVERT EXAMPLE [converter]
Widget byteToStringSection() {
return Column(
children: [
const SizedBox(height: 24),
const Text(
'From Byte Value to String',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16,
),
),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: 2,
child: TextFormField(
controller: dataInputController,
onChanged: (value) {
if (value != '') {
useConverterFromByte();
} else {
dataValueController.text = '';
}
},
),
),
const Padding(
padding: EdgeInsets.fromLTRB(10, 20, 10, 0),
child: Text('='),
),
Expanded(
flex: 1,
child: TextFormField(
controller: dataValueController,
keyboardType: TextInputType.number,
textAlign: TextAlign.center,
enabled: false,
),
),
],
)
],
);
}
}