main.dart
import 'package:flutter/material.dart';
import 'package:testapp/decimal_to_binary.dart';
import './binary_to_decimal.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: Converter(),
);
}
}
class Converter extends StatelessWidget {
const Converter({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Converter App'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => BinaryToDecimal()));
},
child: Text(
'Binary to Decimal Converter',
style: TextStyle(
fontSize: 20,
),
),
),
SizedBox(
height: 30,
),
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => DecimalToBinary()));
},
child: Text(
'Decimal to Binary Converter',
style: TextStyle(
fontSize: 20,
),
),
),
],
),
),
);
}
}
binary_to_decimal.dart
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/src/widgets/placeholder.dart';
import 'package:flutter/widgets.dart';
class BinaryToDecimal extends StatefulWidget {
const BinaryToDecimal({super.key});
@override
State createState() => _BinaryToDecimalState();
}
class _BinaryToDecimalState extends State {
TextEditingController binController = TextEditingController();
int decimalNumber = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Binary TO Decimal Converter'),
),
body: Container(
padding: EdgeInsets.all(30),
child: Column(
children: [
TextField(
controller: binController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Enter Binary Number',
),
),
const SizedBox(
height: 30,
),
ElevatedButton(
onPressed: () {
setState(() {
decimalNumber = int.parse(binController.text, radix: 2);
});
},
child: Text(
'Convert',
style: TextStyle(
fontSize: 30,
),
),
),
SizedBox(
height: 30,
),
Text(
'Decimal Number : ' + decimalNumber.toString(),
style: TextStyle(
fontSize: 30,
),
),
],
),
),
);
}
}
decimal_to_binary.dart
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/src/widgets/placeholder.dart';
class DecimalToBinary extends StatefulWidget {
const DecimalToBinary({super.key});
@override
State createState() => _DecimalToBinaryState();
}
class _DecimalToBinaryState extends State {
TextEditingController decController = TextEditingController();
String binaryNumber = '000';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Decimal TO Binary'),
),
body: Container(
padding: EdgeInsets.all(30),
child: Column(
children: [
TextField(
controller: decController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Enter Decimal Number',
),
),
const SizedBox(
height: 30,
),
ElevatedButton(
onPressed: () {
setState(() {
binaryNumber = int.parse(decController.text).toRadixString(2);
});
},
child: Text(
'Convert',
style: TextStyle(
fontSize: 30,
),
),
),
SizedBox(
height: 30,
),
Text(
'Binary : ' + binaryNumber,
style: TextStyle(
fontSize: 30,
),
),
],
),
),
);
}
}