Working buttons

Better layout
etc.
This commit is contained in:
Морозов Андрей 2021-11-05 02:40:16 +04:00
parent 8786f4de70
commit 6bb06f2521
2 changed files with 99 additions and 83 deletions

View File

@ -1,16 +1,21 @@
import 'package:graphs/src/graph.dart'; import 'package:graphs/src/graph.dart';
import 'dart:math';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'dart:math';
class CurvePainter extends CustomPainter { class CurvePainter extends CustomPainter {
CurvePainter(Graphs gr) {
_gr = gr;
}
Graphs _gr = Graphs();
double rad = 7; double rad = 7;
double width = 4; double width = 4;
Color col = Colors.black; Color col = Colors.black;
double aboveHeight = 3; double aboveHeight = 5;
double circleRad = 100; double circleRad = 100;
TextStyle textStyle = const TextStyle( TextStyle textStyle = const TextStyle(
color: Colors.black, color: Colors.black,
fontSize: 25, fontSize: 21,
); );
void drawLine(Canvas canvas, Offset p1, Offset p2) { 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; double y = sin(2 * pi * i / dotsAm) * circleRad + height;
off[i + 1] = Offset(x, y); off[i + 1] = Offset(x, y);
} }
print(off); //print(off);
return off; return off;
} }
@ -71,7 +76,6 @@ class CurvePainter extends CustomPainter {
var beg = off[i.num]; var beg = off[i.num];
for (var d in list.keys) { for (var d in list.keys) {
drawLine(canvas, beg!, off[d]!); drawLine(canvas, beg!, off[d]!);
print(d);
} }
} }
} }
@ -79,21 +83,21 @@ class CurvePainter extends CustomPainter {
@override @override
void paint(Canvas canvas, Size size) { void paint(Canvas canvas, Size size) {
if (size.width > size.height) { if (size.width > size.height) {
circleRad = size.height / 5; circleRad = size.height / 3;
} else { } else {
circleRad = size.width / 5; circleRad = size.width / 3;
} }
var paint = Paint(); var paint = Paint();
//drawLine(canvas, Offset(0, size.height / 2), //drawLine(canvas, Offset(0, size.height / 2),
//Offset(size.width, size.height / 2)); //Offset(size.width, size.height / 2));
var gr = getGraph(); _gr = getGraph();
var off = getDotPos(gr.getDotAmount(), size); var off = getDotPos(_gr.getDotAmount(), size);
for (int i = 0; i < off.length; i++) { for (int i = 0; i < off.length; i++) {
drawDot(canvas, off[i + 1]!); 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.color = Colors.blue;
paint.style = PaintingStyle.stroke; paint.style = PaintingStyle.stroke;
@ -101,21 +105,11 @@ class CurvePainter extends CustomPainter {
//drawAboveText(canvas, size, "sssssssssssss"); //drawAboveText(canvas, size, "sssssssssssss");
//_drawTextAt("Assss", Offset(size.width / 2, size.height / 2), canvas); //_drawTextAt("Assss", Offset(size.width / 2, size.height / 2), canvas);
paint.color = Colors.green; 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 @override
bool shouldRepaint(CustomPainter oldDelegate) { bool shouldRepaint(CustomPainter oldDelegate) {
return true; return false;
} }
/*void _drawTextAt(String txt, Offset position, Canvas canvas) { /*void _drawTextAt(String txt, Offset position, Canvas canvas) {

View File

@ -1,4 +1,5 @@
import 'dart:io'; import 'dart:io';
import 'dart:math';
import 'package:graphs/curve_painter.dart'; import 'package:graphs/curve_painter.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -13,10 +14,16 @@ class DrawingPage extends StatefulWidget {
} }
class _DrawingPageState extends State<DrawingPage> { class _DrawingPageState extends State<DrawingPage> {
double screenSize = 0;
Graphs data = Graphs("Data"); Graphs data = Graphs("Data");
final _textDot1Controller = TextEditingController();
final _textDot2Controller = TextEditingController();
final _textLenController = TextEditingController();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
screenSize = MediaQuery.of(context).size.width;
return MaterialApp( return MaterialApp(
home: Scaffold( home: Scaffold(
appBar: AppBar( appBar: AppBar(
@ -26,58 +33,27 @@ class _DrawingPageState extends State<DrawingPage> {
flexibleSpace: Container( flexibleSpace: Container(
color: Colors.blue, color: Colors.blue,
child: Column(children: <Widget>[ child: Column(children: <Widget>[
/*Row(children: const <Widget>[
SizedBox(width: 25),
Text("Graph", style: TextStyle(fontSize: 23, color: Colors.white))
]),*/
const SizedBox(height: 5), const SizedBox(height: 5),
Container( Row(children: [
width: MediaQuery.of(context).size.width / 3 + 30, addSpaceW(screenSize / 4 - 20),
height: 40, createInputBox("Input dot1 number", screenSize / 4 - 5,
margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 5), Icons.fiber_manual_record, _textDot1Controller),
child: const TextField( //addSpaceW(4),
textAlign: TextAlign.center, createInputBox("Input dot2 number", screenSize / 4 - 5,
decoration: InputDecoration( Icons.fiber_manual_record, _textDot2Controller),
contentPadding: ]),
EdgeInsets.symmetric(vertical: 10, horizontal: 10), addSpaceH(3),
filled: true, createInputBox("Input path length", screenSize / 3 + 30,
fillColor: Colors.white, Icons.arrow_right_alt_outlined, _textLenController),
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"),
),
),
]), ]),
), ),
actions: [ actions: [
Column( Column(
children: [ children: [
addVerticalSpace(10), addSpaceH(10),
createButton("\nAdd dot\n"), createButton("\nAdd dot\n", addDotPushed),
addVerticalSpace(3), addSpaceH(3),
createButton("\nDel dot \n"), createButton("\nDel dot \n", addLenPushed),
], ],
), ),
IconButton( IconButton(
@ -87,18 +63,19 @@ class _DrawingPageState extends State<DrawingPage> {
), ),
]), ]),
body: CustomPaint( body: CustomPaint(
painter: CurvePainter(), painter: CurvePainter(Graphs()),
child: const Center(), 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( return ElevatedButton(
style: TextButton.styleFrom( /*style: TextButton.styleFrom(
primary: Colors.blue, primary: Colors.blue,
), ),*/
onPressed: null, onPressed: onPressing,
child: Text(txt, child: Text(txt,
style: const TextStyle( style: const TextStyle(
fontSize: 15, fontSize: 15,
@ -108,10 +85,64 @@ class _DrawingPageState extends State<DrawingPage> {
); );
} }
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); 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<String>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: Text(alertTitle),
content: Text(err),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context, 'OK'),
child: const Text('OK'),
),
],
),
);
void closeApp() { void closeApp() {
if (Platform.isWindows) { if (Platform.isWindows) {
exit(0); exit(0);
@ -119,12 +150,3 @@ class _DrawingPageState extends State<DrawingPage> {
SystemChannels.platform.invokeMethod('SystemNavigator.pop'); SystemChannels.platform.invokeMethod('SystemNavigator.pop');
} }
} }
class _Buttons extends StatelessWidget {
const _Buttons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container();
}
}