mirror of
https://github.com/hmalik144/easy_cc_flutter.git
synced 2025-12-10 03:05:34 +00:00
text changed on listeners received
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import 'package:easy_cc_flutter/MainViewModel.dart';
|
import 'package:easy_cc_flutter/MainViewModel.dart';
|
||||||
|
import 'package:easy_cc_flutter/Utils/SelectionType.dart';
|
||||||
import 'package:easy_cc_flutter/views/DropDownBox.dart';
|
import 'package:easy_cc_flutter/views/DropDownBox.dart';
|
||||||
import 'package:easy_cc_flutter/views/EditText.dart';
|
import 'package:easy_cc_flutter/views/EditText.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
@@ -16,6 +17,9 @@ class HomePage extends BaseStatelessWidget<MainViewModel> {
|
|||||||
@override
|
@override
|
||||||
Widget displayWidget(
|
Widget displayWidget(
|
||||||
BuildContext context, MainViewModel model, Widget? child) {
|
BuildContext context, MainViewModel model, Widget? child) {
|
||||||
|
TextEditingController controller1 = TextEditingController();
|
||||||
|
TextEditingController controller2 = TextEditingController();
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
@@ -24,7 +28,9 @@ class HomePage extends BaseStatelessWidget<MainViewModel> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
DropDownBox(model.data, (selected) {}),
|
DropDownBox(model.data, (selected) {}),
|
||||||
EditText("Enter conversion from", model.top, (selection) => {})
|
ConverterEditText("Enter conversion from", controller1, (input) => {
|
||||||
|
controller2.text = model.convertInput(input, SelectionType.conversionFrom)
|
||||||
|
})
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -33,7 +39,9 @@ class HomePage extends BaseStatelessWidget<MainViewModel> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
DropDownBox(model.data, (selected) {}),
|
DropDownBox(model.data, (selected) {}),
|
||||||
EditText("Enter conversion from", model.bottom, (selection) => {})
|
ConverterEditText("Enter conversion from", controller2, (input) => {
|
||||||
|
controller1.text = model.convertInput(input, SelectionType.conversionTo)
|
||||||
|
})
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import 'package:easy_cc_flutter/BaseViewModel.dart';
|
import 'package:easy_cc_flutter/BaseViewModel.dart';
|
||||||
|
import 'package:easy_cc_flutter/Utils/SelectionType.dart';
|
||||||
|
|
||||||
class MainViewModel extends BaseViewmodel {
|
class MainViewModel extends BaseViewmodel {
|
||||||
|
|
||||||
String? top;
|
double conversionRate = 1.4;
|
||||||
String? bottom;
|
|
||||||
|
|
||||||
final List<String> data = <String>['ALL - Albanian Lek',
|
final List<String> data = <String>['ALL - Albanian Lek',
|
||||||
'AFN - Afghan Afghani',
|
'AFN - Afghan Afghani',
|
||||||
@@ -160,4 +160,18 @@ class MainViewModel extends BaseViewmodel {
|
|||||||
'XOF - West African CFA Franc',
|
'XOF - West African CFA Franc',
|
||||||
'YER - Yemeni Rial',
|
'YER - Yemeni Rial',
|
||||||
'ZMW - Zambian Kwacha'];
|
'ZMW - Zambian Kwacha'];
|
||||||
|
|
||||||
|
String convertInput(String? input, SelectionType type) {
|
||||||
|
if (input == null || input.isEmpty) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
double convertedInput = double.parse(input);
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case SelectionType.conversionFrom:
|
||||||
|
return (convertedInput * conversionRate).toStringAsFixed(2);
|
||||||
|
case SelectionType.conversionTo:
|
||||||
|
return (convertedInput / conversionRate).toStringAsFixed(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
4
lib/Utils/SelectionType.dart
Normal file
4
lib/Utils/SelectionType.dart
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
enum SelectionType {
|
||||||
|
conversionFrom,
|
||||||
|
conversionTo
|
||||||
|
}
|
||||||
@@ -1,22 +1,21 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
import '../Utils/Constants.dart';
|
import '../Utils/Constants.dart';
|
||||||
|
|
||||||
class EditText extends StatelessWidget {
|
class ConverterEditText extends StatelessWidget {
|
||||||
final String _hintText;
|
final String _hintText;
|
||||||
final String? _input;
|
|
||||||
final Function(String?) _onChanged;
|
final Function(String?) _onChanged;
|
||||||
|
final TextEditingController _controller;
|
||||||
|
|
||||||
const EditText(this._hintText, this._input, this._onChanged, {super.key});
|
const ConverterEditText(this._hintText, this._controller, this._onChanged, {super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 2, horizontal: 4),
|
padding: const EdgeInsets.symmetric(vertical: 2, horizontal: 4),
|
||||||
child: TextField(
|
child: TextField(
|
||||||
controller: TextEditingController(
|
controller: _controller,
|
||||||
text: _input
|
|
||||||
),
|
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
contentPadding: const EdgeInsets.all(14),
|
contentPadding: const EdgeInsets.all(14),
|
||||||
border: const OutlineInputBorder(
|
border: const OutlineInputBorder(
|
||||||
@@ -28,7 +27,10 @@ class EditText extends StatelessWidget {
|
|||||||
hintText: _hintText,
|
hintText: _hintText,
|
||||||
),
|
),
|
||||||
onChanged: _onChanged,
|
onChanged: _onChanged,
|
||||||
|
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||||
|
inputFormatters: <TextInputFormatter>[
|
||||||
|
FilteringTextInputFormatter.allow(RegExp("[0-9]")),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
10
pubspec.lock
10
pubspec.lock
@@ -134,14 +134,14 @@ packages:
|
|||||||
name: matcher
|
name: matcher
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.12.11"
|
version: "0.12.12"
|
||||||
material_color_utilities:
|
material_color_utilities:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: material_color_utilities
|
name: material_color_utilities
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.1.5"
|
version: "0.2.0"
|
||||||
meta:
|
meta:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -188,7 +188,7 @@ packages:
|
|||||||
name: source_span
|
name: source_span
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.9.0"
|
version: "1.9.1"
|
||||||
stack_trace:
|
stack_trace:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -244,7 +244,7 @@ packages:
|
|||||||
name: test_api
|
name: test_api
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.4.9"
|
version: "0.4.13"
|
||||||
toast:
|
toast:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@@ -279,7 +279,7 @@ packages:
|
|||||||
name: vector_math
|
name: vector_math
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.2"
|
version: "2.1.3"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=2.18.0-190.0.dev <3.0.0"
|
dart: ">=2.18.0-190.0.dev <3.0.0"
|
||||||
flutter: ">=1.20.0"
|
flutter: ">=1.20.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user