release 1.o

This commit is contained in:
denisnadey 2020-10-01 15:20:49 +03:00
parent bdf1318a25
commit 98203a7719
3 changed files with 305 additions and 110 deletions

View File

@ -1 +1,4 @@
include: package:lint/analysis_options.yaml include: package:lint/analysis_options.yaml
analyzer:
enable-experiment:
- extension-methods

View File

@ -1,69 +1,60 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
enum Operation { plus, minus, multi, div, point, res } enum Operation {
enum Numbers { zero, one, two, three, four, five, six, seven, eight, nine } plus,
double a, b; minus,
dynamic operator; multi,
div,
point,
res,
percent,
plusMinus,
backspace,
clear
}
String textResh = "0"; extension OperationExtension on Operation {
String getString() {
void getCalc(dynamic type) { switch (this) {
if (type is Numbers) { case Operation.plus:
if (a == null) { return "+";
a = type.index.toDouble(); case Operation.minus:
print("a: ${a}"); return "-";
} else if (a != null && operator == null) { case Operation.multi:
if (a >= 0) { return "x";
a = (a * 10) + type.index; case Operation.div:
print("a: ${a} - concat"); return "÷";
} case Operation.point:
} else if (operator != null) { return ".";
if (b == null) { case Operation.res:
b = type.index.toDouble(); return "=";
print("b: ${b}"); default:
} else if (b != null) { throw UnimplementedError();
if (b >= 0) {
b = (b * 10) + type.index;
print("b: ${b} - concat");
}
}
} }
} }
if (type is Operation) {
if (type == Operation.res) {
print("счиатаем выполняя : ${operator}");
a = operationEvent(a.toInt(), b.toInt(), operator);
b = null;
print("ответ : ${a}");
} else {
operator = type;
}
print(type);
}
} }
double operationEvent(int x, int y, dynamic op) { enum Numbers { zero, one, two, three, four, five, six, seven, eight, nine }
double result = 0;
switch (op) { extension NumbersExtension on num {
case (Operation.plus): num backspace() {
result = (x + y).toDouble(); String pull = "$this";
break; pull = pull.substring(0, pull.length - 1);
case (Operation.minus): if (pull.isNotEmpty && pull.split('').last.contains('.')) {
result = (x - y).toDouble(); pull = pull.substring(0, pull.length - 1);
break; }
case (Operation.multi): return num.parse(pull, (pull) => 0);
result = (x * y).toDouble(); }
break;
case (Operation.div): num concat({bool pointer, int value}) {
result = (x / y).toDouble(); if (pointer == true) {
break; final String pull = "${this}." + "$value";
default: return num.parse(pull);
result = 0; } else {
break; final String pull = "$this" + "$value";
return num.parse(pull);
}
} }
return result;
} }
void main() { void main() {
@ -94,6 +85,166 @@ class MyHomePage extends StatefulWidget {
} }
class _MyHomePageState extends State<MyHomePage> { class _MyHomePageState extends State<MyHomePage> {
num a, b;
bool pointStatus;
dynamic operator;
String textResh = "0";
void getCalc(dynamic type) {
if (type is Numbers) {
if (a == null) {
a = type.index;
setState(() {
textResh = '$a';
});
} else if (a != null && operator == null) {
if (pointStatus == true) {
a = a.concat(pointer: true, value: type.index);
pointStatus = false;
} else {
a = a.concat(pointer: false, value: type.index);
}
setState(() {
textResh = '$a';
});
} else if (operator != null) {
if (b == null) {
b = type.index;
setState(() {
textResh = "$a ${(operator as Operation).getString()} $b";
});
} else if (b != null) {
if (pointStatus == true) {
b = b.concat(pointer: true, value: type.index);
pointStatus = false;
} else {
b = b.concat(pointer: false, value: type.index);
}
pointStatus = false;
setState(() {
textResh = "$a ${(operator as Operation).getString()} $b";
});
}
}
} else if (type is Operation) {
if (type == Operation.res) {
setState(() {
textResh = "$a ${(operator as Operation).getString()} $b";
});
a = operationEvent(a, b, operator as Operation);
b = null;
operator = null;
setState(() {
textResh = "$a";
});
} else if (type == Operation.point) {
if (a != null && b == null) {
if (a is double) {
pointStatus = false;
setState(() {
textResh = "$a";
});
} else {
pointStatus = true;
setState(() {
textResh = "$a.";
});
}
} else {
if (b is double) {
pointStatus = false;
setState(() {
textResh = "$a ${(operator as Operation).getString()} $b";
});
} else {
pointStatus = true;
setState(() {
textResh = "$a ${(operator as Operation).getString()} $b.";
});
}
}
} else if (type == Operation.clear) {
a = 0;
b = null;
operator = null;
setState(() {
textResh = "$a";
});
} else if (type == Operation.backspace) {
if (a != null && b == null) {
a = a.backspace();
setState(() {
textResh = "$a";
});
} else {
b = b.backspace();
setState(() {
textResh = "$a ${(operator as Operation).getString()} $b";
});
}
} else if (type == Operation.plusMinus) {
if (a != null && b == null) {
a = a * -1;
setState(() {
textResh = "$a";
});
} else {
b = b * -1;
setState(() {
textResh = "$a ${(operator as Operation).getString()} $b";
});
}
} else if (type == Operation.percent) {
if (a != null && b == null) {
a = a / 100;
setState(() {
textResh = "$a";
});
} else {
b = b / 100;
setState(() {
textResh = "$a ${(operator as Operation).getString()} $b";
});
}
} else {
operator = type;
setState(() {
textResh = "$a ${(operator as Operation).getString()}";
});
}
}
}
num operationEvent(num x, num y, Operation op) {
num result = 0;
switch (op) {
case Operation.plus:
result = x + y;
break;
case Operation.minus:
result = x - y;
break;
case Operation.multi:
result = x * y;
break;
case Operation.div:
result = x / y;
break;
default:
result = 0;
break;
}
if (result % 1 == 0) {
return result.toInt();
} else {
return result;
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -111,41 +262,82 @@ class _MyHomePageState extends State<MyHomePage> {
child: Align( child: Align(
alignment: Alignment.centerRight, alignment: Alignment.centerRight,
child: Text( child: Text(
'$textResh', textResh,
style: TextStyle(fontSize: 80, color: Colors.white), style: const TextStyle(fontSize: 80, color: Colors.white),
), ),
), ),
), ),
Row( Row(
children: [ children: [
CallButton(text: "7", value: Numbers.seven), CallButton(
CallButton(text: "8", value: Numbers.eight), text: "±",
CallButton(text: "9", value: Numbers.nine), value: Operation.plusMinus,
CallButton(text: "/", value: Operation.div), onPressed: getCalc,
),
CallButton(
text: "%",
value: Operation.percent,
onPressed: getCalc),
CallButton(
text: "",
value: Operation.backspace,
onPressed: getCalc),
CallButton(
text: "AC", value: Operation.clear, onPressed: getCalc),
], ],
), ),
Row( Row(
children: [ children: [
CallButton(text: "4", value: Numbers.four), CallButton(
CallButton(text: "5", value: Numbers.five), text: "7",
CallButton(text: "6", value: Numbers.six), value: Numbers.seven,
CallButton(text: "*", value: Operation.multi), onPressed: getCalc,
),
CallButton(
text: "8", value: Numbers.eight, onPressed: getCalc),
CallButton(
text: "9", value: Numbers.nine, onPressed: getCalc),
CallButton(
text: "/", value: Operation.div, onPressed: getCalc),
], ],
), ),
Row( Row(
children: [ children: [
CallButton(text: "1", value: Numbers.one), CallButton(
CallButton(text: "2", value: Numbers.two), text: "4", value: Numbers.four, onPressed: getCalc),
CallButton(text: "3", value: Numbers.three), CallButton(
CallButton(text: "-", value: Operation.minus), text: "5", value: Numbers.five, onPressed: getCalc),
CallButton(
text: "6", value: Numbers.six, onPressed: getCalc),
CallButton(
text: "*", value: Operation.multi, onPressed: getCalc),
], ],
), ),
Row( Row(
children: [ children: [
CallButton(text: "0", value: Numbers.zero), CallButton(
CallButton(text: ".", value: Operation.point), text: "1", value: Numbers.one, onPressed: getCalc),
CallButton(text: "=", value: Operation.res), CallButton(
CallButton(text: "+", value: Operation.plus), text: "2", value: Numbers.two, onPressed: getCalc),
CallButton(
text: "3", value: Numbers.three, onPressed: getCalc),
CallButton(
text: "-", value: Operation.minus, onPressed: getCalc),
],
),
Row(
children: [
CallButton(
text: "0", value: Numbers.zero, onPressed: getCalc),
CallButton(
text: ".", value: Operation.point, onPressed: getCalc),
CallButton(
text: "=", value: Operation.res, onPressed: getCalc),
CallButton(
text: "+",
value: Operation.plus,
onPressed: getCalc,
),
], ],
), ),
], ],
@ -156,9 +348,13 @@ class _MyHomePageState extends State<MyHomePage> {
} }
class CallButton extends StatelessWidget { class CallButton extends StatelessWidget {
String text; final String text;
dynamic value; final dynamic value;
CallButton({this.text, this.value});
final void Function(dynamic) onPressed;
const CallButton(
{@required this.text, @required this.value, @required this.onPressed});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -171,16 +367,12 @@ class CallButton extends StatelessWidget {
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
color: const Color(0xE0E0E0E0)), color: const Color(0xE0E0E0E0)),
child: AspectRatio( child: FlatButton(
aspectRatio: 1, height: 60,
child: FlatButton( onPressed: () => onPressed(value),
onPressed: () { child: Text(
getCalc(value); text,
}, style: TextStyle(fontSize: 40, color: Colors.blue[900]),
child: Text(
text,
style: TextStyle(fontSize: 60, color: Colors.blue[900]),
),
), ),
), ),
), ),

View File

@ -7,42 +7,42 @@ packages:
name: async name: async
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.5.0-nullsafety" version: "2.5.0-nullsafety.1"
boolean_selector: boolean_selector:
dependency: transitive dependency: transitive
description: description:
name: boolean_selector name: boolean_selector
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0-nullsafety" version: "2.1.0-nullsafety.1"
characters: characters:
dependency: transitive dependency: transitive
description: description:
name: characters name: characters
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.0-nullsafety.2" version: "1.1.0-nullsafety.3"
charcode: charcode:
dependency: transitive dependency: transitive
description: description:
name: charcode name: charcode
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0-nullsafety" version: "1.2.0-nullsafety.1"
clock: clock:
dependency: transitive dependency: transitive
description: description:
name: clock name: clock
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.0-nullsafety" version: "1.1.0-nullsafety.1"
collection: collection:
dependency: transitive dependency: transitive
description: description:
name: collection name: collection
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.15.0-nullsafety.2" version: "1.15.0-nullsafety.3"
cupertino_icons: cupertino_icons:
dependency: "direct main" dependency: "direct main"
description: description:
@ -56,7 +56,7 @@ packages:
name: fake_async name: fake_async
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.0-nullsafety" version: "1.2.0-nullsafety.1"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
@ -73,28 +73,28 @@ packages:
name: lint name: lint
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0" version: "1.3.0"
matcher: matcher:
dependency: transitive dependency: transitive
description: description:
name: matcher name: matcher
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.12.10-nullsafety" version: "0.12.10-nullsafety.1"
meta: meta:
dependency: transitive dependency: transitive
description: description:
name: meta name: meta
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.0-nullsafety.2" version: "1.3.0-nullsafety.3"
path: path:
dependency: transitive dependency: transitive
description: description:
name: path name: path
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.0-nullsafety" version: "1.8.0-nullsafety.1"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
@ -106,55 +106,55 @@ packages:
name: source_span name: source_span
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.0-nullsafety" version: "1.8.0-nullsafety.2"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
name: stack_trace name: stack_trace
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.10.0-nullsafety" version: "1.10.0-nullsafety.1"
stream_channel: stream_channel:
dependency: transitive dependency: transitive
description: description:
name: stream_channel name: stream_channel
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0-nullsafety" version: "2.1.0-nullsafety.1"
string_scanner: string_scanner:
dependency: transitive dependency: transitive
description: description:
name: string_scanner name: string_scanner
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.0-nullsafety" version: "1.1.0-nullsafety.1"
term_glyph: term_glyph:
dependency: transitive dependency: transitive
description: description:
name: term_glyph name: term_glyph
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0-nullsafety" version: "1.2.0-nullsafety.1"
test_api: test_api:
dependency: transitive dependency: transitive
description: description:
name: test_api name: test_api
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.2.19-nullsafety" version: "0.2.19-nullsafety.2"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
name: typed_data name: typed_data
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.0-nullsafety.2" version: "1.3.0-nullsafety.3"
vector_math: vector_math:
dependency: transitive dependency: transitive
description: description:
name: vector_math name: vector_math
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0-nullsafety.2" version: "2.1.0-nullsafety.3"
sdks: sdks:
dart: ">=2.10.0-0.0.dev <2.10.0" dart: ">=2.10.0-110 <2.11.0"