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
A new Flutter project.
## 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.
Generátor příkladů pro subnetování sítí

View file

@ -2,6 +2,23 @@ import 'package:flutter/material.dart';
import 'package:pavouk/okna/domov.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() {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp());

View file

@ -8,6 +8,23 @@ import 'package:pavouk/util/subnet_masky.dart';
import 'package:pavouk/util/vzhled.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 {
const DomovskaStrana({super.key});
@ -254,6 +271,38 @@ class _DomovskaStranaState extends State<DomovskaStrana> {
);
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(
context,
MaterialPageRoute(
@ -281,6 +330,11 @@ class _DomovskaStranaState extends State<DomovskaStrana> {
),
);
}
var subnety = Util.subnety()
.where(
(element) => element["hosti"]! > maxPocetRealnych,
)
.toList();
Random rnd = Random();
// vytvořit zdrojovou IP
var ip = "";
@ -301,8 +355,9 @@ class _DomovskaStranaState extends State<DomovskaStrana> {
}
subnetData.add(rnd.nextInt(maxPocetRealnych) + 2);
}
var maska = subnety[rnd.nextInt(subnety.length)];
// vložit
_origoController.text = "$ip/22";
_origoController.text = "$ip/${maska['prefix']}";
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: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 {
const Reseni({super.key, required this.origoIp, required this.subnety});
final String origoIp;
@ -123,19 +140,20 @@ class _ReseniState extends State<Reseni> {
children: [
Text(
"Zadaná IP:",
style: Vzhled.tableContent,
style: Vzhled.tableContent(context),
),
const SizedBox(
width: 20,
),
Text(origoNetIP, style: Vzhled.tableContent)
Text(origoNetIP, style: Vzhled.tableContent(context))
],
),
DefaultTextStyle(
style: Vzhled.tableContent,
style: Vzhled.tableContent(context),
child: Expanded(
child: Table(
border: TableBorder.all(),
border: TableBorder.all(
color: Theme.of(context).colorScheme.inverseSurface),
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
defaultColumnWidth: FixedColumnWidth(
Device.orientation == Orientation.landscape
@ -247,29 +265,61 @@ class _ReseniState extends State<Reseni> {
style: Vzhled.text, textAlign: TextAlign.center),
),
TableCell(
child: SizedBox(
height: 50,
child: Center(
child: Text(
widget.subnety[i].toString(),
textAlign: TextAlign.center,
),
),
)),
TableCell(
child: SizedBox(
height: 50,
child: Center(
child: Text((prefix["hosti"]! - 2).toString(),
textAlign: TextAlign.center)),
textAlign: TextAlign.center),
),
)),
TableCell(
child: Text(ip, textAlign: TextAlign.center),
child: SizedBox(
height: 50,
child: Center(child: Text(ip, textAlign: TextAlign.center))),
),
TableCell(
child:
Text(prefix["prefix"]!.toString(), textAlign: TextAlign.center),
child: SizedBox(
height: 50,
child: Center(
child: Text(prefix["prefix"]!.toString(),
textAlign: TextAlign.center),
),
),
),
TableCell(
child: SizedBox(
height: 50,
child: Center(
child: Text(prvni, textAlign: TextAlign.center),
),
TableCell(
child: Text(posledni, textAlign: TextAlign.center),
),
),
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),
),
),
),
]));
}
setState(() {});

View file

@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'dart:html' as html;
AppBar bar(BuildContext context, {int i = 0}) => AppBar(
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(
icon: const Icon(Icons.info_outline),
onPressed: () {
PackageInfo.fromPlatform().then((v) => showAboutDialog(
PackageInfo.fromPlatform().then(
(v) => showAboutDialog(
context: context,
applicationName: "Pavouk",
applicationVersion: v.version,
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 {
static List<Map<String, int>> subnety() {
var list = <Map<String, int>>[
@ -17,12 +15,10 @@ class Util {
static List<String> _strToBin(String input) {
var list = <String>[];
input.split(".").forEach((numero) {
print(numero);
var bin = int.parse(numero).toRadixString(2);
while (bin.length < 8) {
bin = "0$bin";
}
print(bin);
list.add(bin);
});
return list;
@ -52,9 +48,7 @@ class Util {
static String ipToNetworkAdd(String ip, String nm) {
var nmBin = _strToBin(nm);
print(nmBin);
var ipBin = _strToBin(ip);
print(ipBin);
var networkAdd = <String>[];
for (int i = 0; i < 4; i++) {

View file

@ -14,5 +14,6 @@ class Vzhled {
static final ButtonStyle tlacitkoStyl =
ButtonStyle(backgroundColor: MaterialStateProperty.all(Colors.red));
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
version: 1.0.0+1
version: 1.1.0+2
environment:
sdk: '>=2.18.2 <3.0.0'