From e31e77411540e91c5d4f468ffb4d0c5c498ba5ac Mon Sep 17 00:00:00 2001 From: lnd212 Date: Fri, 5 Nov 2021 04:23:20 +0400 Subject: [PATCH] FL:Del dot working GR:DelDot return error string --- flutter/lib/pages/drawing_page.dart | 50 +++++++++++++++-------------- flutter/lib/src/graph.dart | 7 ++-- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/flutter/lib/pages/drawing_page.dart b/flutter/lib/pages/drawing_page.dart index 43edc78..35f31df 100644 --- a/flutter/lib/pages/drawing_page.dart +++ b/flutter/lib/pages/drawing_page.dart @@ -27,12 +27,12 @@ class _DrawingPageState extends State { Graphs data = getGraph(); final _textNameController = TextEditingController(); - final _textInptController = TextEditingController(); + final _textNumbController = TextEditingController(); final _textDistController = TextEditingController(); final _textLnthController = TextEditingController(); void clearTextControllers() { _textDistController.clear(); - _textInptController.clear(); + _textNumbController.clear(); _textLnthController.clear(); _textNameController.clear(); } @@ -51,14 +51,14 @@ class _DrawingPageState extends State { child: Column(children: [ const SizedBox(height: 5), Row(children: [ - addSpaceW(screenSize / 8 - 20), + addSpaceW(screenSize / 8), createButton("\nAdd dot\n", addDotPushed), createInputBox("Dot name", screenSize / 4 - 25, Icons.label, _textNameController), addSpaceW(20), createButton("\nDel dot \n", delDotPushed), createInputBox("Dot number", screenSize / 4 - 25, - Icons.fiber_manual_record, _textInptController), + Icons.fiber_manual_record, _textNumbController), ]), addSpaceH(3), Row(children: [ @@ -69,27 +69,27 @@ class _DrawingPageState extends State { createInputBox("Input length", screenSize / 4 - 5, Icons.arrow_right_alt_outlined, _textLnthController), ]), - //createInputBox("Input path length", screenSize / 3 + 30, Icons.arrow_right_alt_outlined, _textLenController), ]), ), actions: [ - /*Column( - children: [ - addSpaceH(10), - createButton("\nAdd dot\n", addDotPushed), - addSpaceH(3), - createButton("\nDel dot \n", addLenPushed), - ], - ),*/ IconButton( - onPressed: () => flushData(), + onPressed: flushData, icon: const Icon(Icons.delete_sweep), iconSize: 60, ), ]), body: CustomPaint( painter: CurvePainter(gr: data), - child: const Center(), + child: Align( + alignment: Alignment.topRight, + child: ButtonBar( + mainAxisSize: MainAxisSize.min, + children: [ + createButton("Hello", () {}), + createButton("Hi", () {}), + ], + ), + ), ), )); } @@ -97,9 +97,6 @@ class _DrawingPageState extends State { // ignore: avoid_types_as_parameter_names, non_constant_identifier_names, use_function_type_syntax_for_parameters ElevatedButton createButton(String txt, void onPressing()) { return ElevatedButton( - /*style: TextButton.styleFrom( - primary: Colors.blue, - ),*/ onPressed: onPressing, child: Text(txt, style: const TextStyle( @@ -156,12 +153,17 @@ class _DrawingPageState extends State { } void delDotPushed() { - if (_textNameController.text == "") { - showPopUp("Error", "No name in \"Dot name\" box"); + if (_textNumbController.text == "") { + showPopUp("Error", "No number in \"Dot number\" box"); } else { - String? res = data.addIsolated(_textNameController.text); - if (res != null) { - showPopUp("Error", res); + int? dot = int.tryParse(_textNumbController.text); + if (dot == null) { + showPopUp("Error", "Can't parse input.\nInts only allowed"); + } else { + String? res = data.delDot(dot); + if (res != null) { + showPopUp("Error", res); + } } } clearTextControllers(); @@ -170,7 +172,7 @@ class _DrawingPageState extends State { void addLenPushed() { //data.delDot() print( - "${_textInptController.text} -> ${_textDistController.text} = ${_textLnthController.text}"); + "${_textNumbController.text} -> ${_textDistController.text} = ${_textLnthController.text}"); clearTextControllers(); } diff --git a/flutter/lib/src/graph.dart b/flutter/lib/src/graph.dart index cfcb8d2..ef05c6c 100644 --- a/flutter/lib/src/graph.dart +++ b/flutter/lib/src/graph.dart @@ -157,7 +157,10 @@ class Graphs { return true; } - bool delDot(int inn) { + String? delDot(int inn) { + if (inn > _amount || inn < 1) { + return "Index out of range. Allowed 1..$_amount"; + } List toDel = []; for (int i in _dots[inn - 1].getL().keys) { toDel.add(i); @@ -169,7 +172,7 @@ class Graphs { _syncNum(); _syncNameTable(); _fixAfterDel(inn); - return true; + return null; } //*********Delete*********