import 'dart:io'; import 'dart:math'; import 'package:graphs/curve_painter.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:graphs/src/graph.dart'; class DrawingPage extends StatefulWidget { const DrawingPage({Key? key}) : super(key: key); @override State createState() => _DrawingPageState(); } 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( title: const Text("Graph", style: TextStyle(fontSize: 35, color: Colors.white)), toolbarHeight: 110, // Set this height flexibleSpace: Container( color: Colors.blue, child: Column(children: [ const SizedBox(height: 5), 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: [ addSpaceH(10), createButton("\nAdd dot\n", addDotPushed), addSpaceH(3), createButton("\nDel dot \n", addLenPushed), ], ), IconButton( onPressed: () => closeApp(), icon: const Icon(Icons.close), iconSize: 50, ), ]), body: CustomPaint( painter: CurvePainter(Graphs()), child: const Center(), ), )); } // 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( fontSize: 15, color: Colors.white, height: 1, )), ); } 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); } SystemChannels.platform.invokeMethod('SystemNavigator.pop'); } }