feat: vylepšit generování náhodných příkladů a vzhled

This commit is contained in:
Matyáš Caras 2022-11-06 17:04:49 +01:00
parent 5ff8780686
commit 03f47cc38b
9 changed files with 1249 additions and 42 deletions

View file

@ -1,16 +1,3 @@
# pavouk # pavouk
A new Flutter project. Generátor příkladů pro subnetování sítí
## Getting Started
This project is a starting point for a Flutter application.
A few resources to get you started if this is your first Flutter project:
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.

View file

@ -2,6 +2,23 @@ import 'package:flutter/material.dart';
import 'package:pavouk/okna/domov.dart'; import 'package:pavouk/okna/domov.dart';
import 'package:responsive_sizer/responsive_sizer.dart'; import 'package:responsive_sizer/responsive_sizer.dart';
/*
Copyright (C) 2022 Matyáš Caras
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
void main() { void main() {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp()); runApp(const MyApp());

View file

@ -8,6 +8,23 @@ import 'package:pavouk/util/subnet_masky.dart';
import 'package:pavouk/util/vzhled.dart'; import 'package:pavouk/util/vzhled.dart';
import 'package:responsive_sizer/responsive_sizer.dart'; import 'package:responsive_sizer/responsive_sizer.dart';
/*
Copyright (C) 2022 Matyáš Caras
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
class DomovskaStrana extends StatefulWidget { class DomovskaStrana extends StatefulWidget {
const DomovskaStrana({super.key}); const DomovskaStrana({super.key});
@ -254,6 +271,38 @@ class _DomovskaStranaState extends State<DomovskaStrana> {
); );
return; return;
} }
var prefix = int.tryParse(_origoController.text.split("/")[1]);
var sub = Util.subnety()
.where((element) => element["prefix"]! == (prefix ?? 90))
.toList();
if (sub.isEmpty) {
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
"Nezadali jste platný subnet prefix.",
style: TextStyle(fontSize: 12.sp),
),
),
);
return;
}
var pocet = 0;
for (var subPocet in subnety) {
pocet += subPocet;
}
if (sub[0]["hosti"]! < pocet) {
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
"Prefix nemá tolik hostů.",
style: TextStyle(fontSize: 12.sp),
),
),
);
return;
}
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
@ -281,6 +330,11 @@ class _DomovskaStranaState extends State<DomovskaStrana> {
), ),
); );
} }
var subnety = Util.subnety()
.where(
(element) => element["hosti"]! > maxPocetRealnych,
)
.toList();
Random rnd = Random(); Random rnd = Random();
// vytvořit zdrojovou IP // vytvořit zdrojovou IP
var ip = ""; var ip = "";
@ -301,8 +355,9 @@ class _DomovskaStranaState extends State<DomovskaStrana> {
} }
subnetData.add(rnd.nextInt(maxPocetRealnych) + 2); subnetData.add(rnd.nextInt(maxPocetRealnych) + 2);
} }
var maska = subnety[rnd.nextInt(subnety.length)];
// vložit // vložit
_origoController.text = "$ip/22"; _origoController.text = "$ip/${maska['prefix']}";
generovatSubnetFieldy(pocetSubnetu, hodnoty: subnetData); generovatSubnetFieldy(pocetSubnetu, hodnoty: subnetData);
} }
} }

View file

@ -4,6 +4,23 @@ import 'package:pavouk/util/subnet_masky.dart';
import 'package:pavouk/util/vzhled.dart'; import 'package:pavouk/util/vzhled.dart';
import 'package:responsive_sizer/responsive_sizer.dart'; import 'package:responsive_sizer/responsive_sizer.dart';
/*
Copyright (C) 2022 Matyáš Caras
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
class Reseni extends StatefulWidget { class Reseni extends StatefulWidget {
const Reseni({super.key, required this.origoIp, required this.subnety}); const Reseni({super.key, required this.origoIp, required this.subnety});
final String origoIp; final String origoIp;
@ -123,19 +140,20 @@ class _ReseniState extends State<Reseni> {
children: [ children: [
Text( Text(
"Zadaná IP:", "Zadaná IP:",
style: Vzhled.tableContent, style: Vzhled.tableContent(context),
), ),
const SizedBox( const SizedBox(
width: 20, width: 20,
), ),
Text(origoNetIP, style: Vzhled.tableContent) Text(origoNetIP, style: Vzhled.tableContent(context))
], ],
), ),
DefaultTextStyle( DefaultTextStyle(
style: Vzhled.tableContent, style: Vzhled.tableContent(context),
child: Expanded( child: Expanded(
child: Table( child: Table(
border: TableBorder.all(), border: TableBorder.all(
color: Theme.of(context).colorScheme.inverseSurface),
defaultVerticalAlignment: TableCellVerticalAlignment.middle, defaultVerticalAlignment: TableCellVerticalAlignment.middle,
defaultColumnWidth: FixedColumnWidth( defaultColumnWidth: FixedColumnWidth(
Device.orientation == Orientation.landscape Device.orientation == Orientation.landscape
@ -247,29 +265,61 @@ class _ReseniState extends State<Reseni> {
style: Vzhled.text, textAlign: TextAlign.center), style: Vzhled.text, textAlign: TextAlign.center),
), ),
TableCell( TableCell(
child: SizedBox(
height: 50,
child: Center(
child: Text( child: Text(
widget.subnety[i].toString(), widget.subnety[i].toString(),
textAlign: TextAlign.center, textAlign: TextAlign.center,
),
),
)), )),
TableCell( TableCell(
child: SizedBox(
height: 50,
child: Center(
child: Text((prefix["hosti"]! - 2).toString(), child: Text((prefix["hosti"]! - 2).toString(),
textAlign: TextAlign.center)), textAlign: TextAlign.center),
),
)),
TableCell( TableCell(
child: Text(ip, textAlign: TextAlign.center), child: SizedBox(
height: 50,
child: Center(child: Text(ip, textAlign: TextAlign.center))),
), ),
TableCell( TableCell(
child: child: SizedBox(
Text(prefix["prefix"]!.toString(), textAlign: TextAlign.center), height: 50,
child: Center(
child: Text(prefix["prefix"]!.toString(),
textAlign: TextAlign.center),
),
),
), ),
TableCell( TableCell(
child: SizedBox(
height: 50,
child: Center(
child: Text(prvni, textAlign: TextAlign.center), child: Text(prvni, textAlign: TextAlign.center),
), ),
TableCell( ),
child: Text(posledni, textAlign: TextAlign.center),
), ),
TableCell( TableCell(
child: SizedBox(
height: 50,
child: Center(
child: Text(posledni, textAlign: TextAlign.center),
),
),
),
TableCell(
child: SizedBox(
height: 50,
child: Center(
child: Text(broadcast, textAlign: TextAlign.center), child: Text(broadcast, textAlign: TextAlign.center),
), ),
),
),
])); ]));
} }
setState(() {}); setState(() {});

View file

@ -1,5 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:package_info_plus/package_info_plus.dart'; import 'package:package_info_plus/package_info_plus.dart';
import 'dart:html' as html;
AppBar bar(BuildContext context, {int i = 0}) => AppBar( AppBar bar(BuildContext context, {int i = 0}) => AppBar(
title: const Text('Pavouk - generátor příkladů pro výuku subnetování'), title: const Text('Pavouk - generátor příkladů pro výuku subnetování'),
@ -9,12 +10,20 @@ AppBar bar(BuildContext context, {int i = 0}) => AppBar(
IconButton( IconButton(
icon: const Icon(Icons.info_outline), icon: const Icon(Icons.info_outline),
onPressed: () { onPressed: () {
PackageInfo.fromPlatform().then((v) => showAboutDialog( PackageInfo.fromPlatform().then(
(v) => showAboutDialog(
context: context, context: context,
applicationName: "Pavouk", applicationName: "Pavouk",
applicationVersion: v.version, applicationVersion: v.version,
applicationLegalese: applicationLegalese:
"© 2022 Matyáš Caras\nVydáno pod licencí GNU AGPLv3\nVěnováno SŠTE Brno, Olomoucká")); "© 2022 Matyáš Caras\nVydáno pod licencí GNU AGPLv3\nVěnováno SŠTE Brno, Olomoucká",
children: [
TextButton(
onPressed: () => html.window.open(
"https://github.com/hernikplays/pavouk", "_blank"),
child: const Text("Zdrojový kód"))
]),
);
}, },
) )
], ],

View file

@ -1,5 +1,3 @@
import 'dart:math';
class Util { class Util {
static List<Map<String, int>> subnety() { static List<Map<String, int>> subnety() {
var list = <Map<String, int>>[ var list = <Map<String, int>>[
@ -17,12 +15,10 @@ class Util {
static List<String> _strToBin(String input) { static List<String> _strToBin(String input) {
var list = <String>[]; var list = <String>[];
input.split(".").forEach((numero) { input.split(".").forEach((numero) {
print(numero);
var bin = int.parse(numero).toRadixString(2); var bin = int.parse(numero).toRadixString(2);
while (bin.length < 8) { while (bin.length < 8) {
bin = "0$bin"; bin = "0$bin";
} }
print(bin);
list.add(bin); list.add(bin);
}); });
return list; return list;
@ -52,9 +48,7 @@ class Util {
static String ipToNetworkAdd(String ip, String nm) { static String ipToNetworkAdd(String ip, String nm) {
var nmBin = _strToBin(nm); var nmBin = _strToBin(nm);
print(nmBin);
var ipBin = _strToBin(ip); var ipBin = _strToBin(ip);
print(ipBin);
var networkAdd = <String>[]; var networkAdd = <String>[];
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {

View file

@ -14,5 +14,6 @@ class Vzhled {
static final ButtonStyle tlacitkoStyl = static final ButtonStyle tlacitkoStyl =
ButtonStyle(backgroundColor: MaterialStateProperty.all(Colors.red)); ButtonStyle(backgroundColor: MaterialStateProperty.all(Colors.red));
static final TextStyle text = TextStyle(fontSize: 13.sp); static final TextStyle text = TextStyle(fontSize: 13.sp);
static final TextStyle tableContent = TextStyle(fontSize: 11.sp); static TextStyle tableContent(context) => TextStyle(
fontSize: 11.sp, color: Theme.of(context).colorScheme.inverseSurface);
} }

1094
pnpm-lock.yaml Normal file

File diff suppressed because it is too large Load diff

View file

@ -3,7 +3,7 @@ description: Generátor příkladu k výuce subnetování
publish_to: 'none' # Remove this line if you wish to publish to pub.dev publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1 version: 1.1.0+2
environment: environment:
sdk: '>=2.18.2 <3.0.0' sdk: '>=2.18.2 <3.0.0'