dart_unit_converter 0.0.1+1 dart_unit_converter: ^0.0.1+1 copied to clipboard
A data unit converter package.
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 = UnitConverter();
final controller = TextEditingController();
final valueListener = ValueNotifier<String>('');
void useConverterFromByte() {
final parsedValue = int.parse(controller.text);
valueListener.value = converter.continousDataConvert(parsedValue);
}
@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.start,
children: [
const SizedBox(height: 24),
const Text('From Byte Value'),
TextFormField(
controller: controller,
keyboardType: TextInputType.number,
),
const SizedBox(height: 50),
ValueListenableBuilder<String>(
valueListenable: valueListener,
builder: (context, value, widget) {
return Center(
child: Text('Value Converted: ${valueListener.value}'),
);
},
),
],
),
),
floatingActionButton: ElevatedButton(
onPressed: () => useConverterFromByte(),
child: const Padding(
padding: EdgeInsets.all(8),
child: Text('Convert Data'),
),
),
);
}
}