diff --git a/flutter/lib/curve_painter.dart b/flutter/lib/curve_painter.dart index 50036d4..3959893 100644 --- a/flutter/lib/curve_painter.dart +++ b/flutter/lib/curve_painter.dart @@ -1,16 +1,21 @@ import 'package:graphs/src/graph.dart'; -import 'dart:math'; import 'package:flutter/material.dart'; +import 'dart:math'; class CurvePainter extends CustomPainter { + CurvePainter(Graphs gr) { + _gr = gr; + } + + Graphs _gr = Graphs(); double rad = 7; double width = 4; Color col = Colors.black; - double aboveHeight = 3; + double aboveHeight = 5; double circleRad = 100; TextStyle textStyle = const TextStyle( color: Colors.black, - fontSize: 25, + fontSize: 21, ); void drawLine(Canvas canvas, Offset p1, Offset p2) { @@ -61,7 +66,7 @@ class CurvePainter extends CustomPainter { double y = sin(2 * pi * i / dotsAm) * circleRad + height; off[i + 1] = Offset(x, y); } - print(off); + //print(off); return off; } @@ -71,7 +76,6 @@ class CurvePainter extends CustomPainter { var beg = off[i.num]; for (var d in list.keys) { drawLine(canvas, beg!, off[d]!); - print(d); } } } @@ -79,21 +83,21 @@ class CurvePainter extends CustomPainter { @override void paint(Canvas canvas, Size size) { if (size.width > size.height) { - circleRad = size.height / 5; + circleRad = size.height / 3; } else { - circleRad = size.width / 5; + circleRad = size.width / 3; } var paint = Paint(); //drawLine(canvas, Offset(0, size.height / 2), //Offset(size.width, size.height / 2)); - var gr = getGraph(); - var off = getDotPos(gr.getDotAmount(), size); + _gr = getGraph(); + var off = getDotPos(_gr.getDotAmount(), size); for (int i = 0; i < off.length; i++) { drawDot(canvas, off[i + 1]!); - drawAboveText(canvas, off[i + 1]!, gr.getDots()[i].getName()); + drawAboveText(canvas, off[i + 1]!, _gr.getDots()[i].getName()); } - drawConnections(canvas, gr.getDots(), off); + drawConnections(canvas, _gr.getDots(), off); paint.color = Colors.blue; paint.style = PaintingStyle.stroke; @@ -101,21 +105,11 @@ class CurvePainter extends CustomPainter { //drawAboveText(canvas, size, "sssssssssssss"); //_drawTextAt("Assss", Offset(size.width / 2, size.height / 2), canvas); paint.color = Colors.green; - - var path = Path(); - path.moveTo(size.width / 3, size.height * 3 / 4); - path.lineTo(size.width / 2, size.height * 5 / 6); - path.lineTo(size.width * 3 / 4, size.height * 4 / 6); - path.close(); - - paint.style = PaintingStyle.fill; - - //canvas.drawPath(path, paint); } @override bool shouldRepaint(CustomPainter oldDelegate) { - return true; + return false; } /*void _drawTextAt(String txt, Offset position, Canvas canvas) { diff --git a/flutter/lib/pages/drawing_page.dart b/flutter/lib/pages/drawing_page.dart index 85c0bf0..952f05d 100644 --- a/flutter/lib/pages/drawing_page.dart +++ b/flutter/lib/pages/drawing_page.dart @@ -1,4 +1,5 @@ import 'dart:io'; +import 'dart:math'; import 'package:graphs/curve_painter.dart'; import 'package:flutter/material.dart'; @@ -13,10 +14,16 @@ class DrawingPage extends StatefulWidget { } class _DrawingPageState extends State { + double screenSize = 0; Graphs data = Graphs("Data"); + final _textDot1Controller = TextEditingController(); + final _textDot2Controller = TextEditingController(); + final _textLenController = TextEditingController(); + @override Widget build(BuildContext context) { + screenSize = MediaQuery.of(context).size.width; return MaterialApp( home: Scaffold( appBar: AppBar( @@ -26,58 +33,27 @@ class _DrawingPageState extends State { flexibleSpace: Container( color: Colors.blue, child: Column(children: [ - /*Row(children: const [ - SizedBox(width: 25), - Text("Graph", style: TextStyle(fontSize: 23, color: Colors.white)) - ]),*/ const SizedBox(height: 5), - Container( - width: MediaQuery.of(context).size.width / 3 + 30, - height: 40, - margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 5), - child: const TextField( - textAlign: TextAlign.center, - decoration: InputDecoration( - contentPadding: - EdgeInsets.symmetric(vertical: 10, horizontal: 10), - filled: true, - fillColor: Colors.white, - prefixIcon: Icon(Icons.fiber_manual_record_outlined, - color: Colors.black), - border: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(40))), - hintStyle: TextStyle(color: Colors.black38), - hintText: "Input dot number"), - ), - ), - Container( - width: MediaQuery.of(context).size.width / 3 + 30, - height: 40, - margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 5), - child: const TextField( - textAlign: TextAlign.center, - decoration: InputDecoration( - contentPadding: - EdgeInsets.symmetric(vertical: 10, horizontal: 10), - filled: true, - fillColor: Colors.white, - prefixIcon: Icon(Icons.arrow_right_alt_outlined, - color: Colors.black), - border: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(40))), - hintStyle: TextStyle(color: Colors.black38), - hintText: "Input path length"), - ), - ), + Row(children: [ + addSpaceW(screenSize / 4 - 20), + createInputBox("Input dot1 number", screenSize / 4 - 5, + Icons.fiber_manual_record, _textDot1Controller), + //addSpaceW(4), + createInputBox("Input dot2 number", screenSize / 4 - 5, + Icons.fiber_manual_record, _textDot2Controller), + ]), + addSpaceH(3), + createInputBox("Input path length", screenSize / 3 + 30, + Icons.arrow_right_alt_outlined, _textLenController), ]), ), actions: [ Column( children: [ - addVerticalSpace(10), - createButton("\nAdd dot\n"), - addVerticalSpace(3), - createButton("\nDel dot \n"), + addSpaceH(10), + createButton("\nAdd dot\n", addDotPushed), + addSpaceH(3), + createButton("\nDel dot \n", addLenPushed), ], ), IconButton( @@ -87,18 +63,19 @@ class _DrawingPageState extends State { ), ]), body: CustomPaint( - painter: CurvePainter(), + painter: CurvePainter(Graphs()), child: const Center(), ), )); } - ElevatedButton createButton(String txt) { + // 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( + /*style: TextButton.styleFrom( primary: Colors.blue, - ), - onPressed: null, + ),*/ + onPressed: onPressing, child: Text(txt, style: const TextStyle( fontSize: 15, @@ -108,10 +85,64 @@ class _DrawingPageState extends State { ); } - SizedBox addVerticalSpace(double h) { + Container createInputBox(String text, double wid, IconData icon, + TextEditingController controller) { + return Container( + width: wid, + height: 40, + margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 5), + child: TextField( + controller: controller, + textAlign: TextAlign.center, + decoration: InputDecoration( + contentPadding: + const EdgeInsets.symmetric(vertical: 10, horizontal: 10), + filled: true, + fillColor: Colors.white, + prefixIcon: Icon(icon, color: Colors.black), + border: const OutlineInputBorder( + borderRadius: BorderRadius.all(Radius.circular(40))), + hintStyle: const TextStyle(color: Colors.black38), + hintText: text), + )); + } + + SizedBox addSpaceH(double h) { return SizedBox(height: h); } + SizedBox addSpaceW(double w) { + return SizedBox(width: w); + } + + void addDotPushed() { + showPopUp("Test", "Test message"); + print(_textDot1Controller.text); + _textDot1Controller.clear(); + } + + void addLenPushed() { + print( + "${_textDot1Controller.text} -> ${_textDot2Controller.text} = ${_textLenController.text}"); + _textDot1Controller.clear(); + _textDot2Controller.clear(); + _textLenController.clear(); + } + + void showPopUp(String alertTitle, String err) => showDialog( + context: context, + builder: (BuildContext context) => AlertDialog( + title: Text(alertTitle), + content: Text(err), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context, 'OK'), + child: const Text('OK'), + ), + ], + ), + ); + void closeApp() { if (Platform.isWindows) { exit(0); @@ -119,12 +150,3 @@ class _DrawingPageState extends State { SystemChannels.platform.invokeMethod('SystemNavigator.pop'); } } - -class _Buttons extends StatelessWidget { - const _Buttons({Key? key}) : super(key: key); - - @override - Widget build(BuildContext context) { - return Container(); - } -}