subfolder for breadcrumb page

correct title
This commit is contained in:
lukas-heiligenbrunner 2022-12-09 12:50:58 +01:00
parent ceeae0523e
commit 4e7694f653
7 changed files with 302 additions and 274 deletions

View File

@ -3,10 +3,11 @@ import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
Future<Map<String, dynamic>> getJson(String uri) async {
dynamic getJson(String uri) async {
if (!kIsWeb) {
uri = "http://127.0.0.1:8000$uri";
}
final resp = await http.get(Uri.parse(uri));
print(resp.body);
return jsonDecode(resp.body);
}

201
app/lib/app.dart Normal file
View File

@ -0,0 +1,201 @@
import 'package:flutter/material.dart';
import 'package:raid_manager/raid_page.dart';
import 'package:sidebarx/sidebarx.dart';
import 'disk_page.dart';
class App extends StatelessWidget {
App({Key? key}) : super(key: key);
final _controller = SidebarXController(selectedIndex: 0, extended: true);
final _key = GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Raid Manager',
theme: ThemeData(
primaryColor: primaryColor,
canvasColor: canvasColor,
scaffoldBackgroundColor: scaffoldBackgroundColor,
textTheme: const TextTheme(
headlineSmall: TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.w800,
),
headlineMedium: TextStyle(
color: Colors.white,
fontSize: 17,
fontWeight: FontWeight.w500,
),
labelMedium: TextStyle(
color: Colors.white,
fontSize: 14,
fontWeight: FontWeight.w200)),
),
home: Builder(
builder: (context) {
final isSmallScreen = MediaQuery.of(context).size.width < 600;
return Scaffold(
key: _key,
appBar: isSmallScreen
? AppBar(
backgroundColor: canvasColor,
title: Text(_getTitleByIndex(_controller.selectedIndex)),
leading: IconButton(
onPressed: () {
// if (!Platform.isAndroid && !Platform.isIOS) {
// _controller.setExtended(true);
// }
_key.currentState?.openDrawer();
},
icon: const Icon(Icons.menu),
),
)
: null,
drawer: ExampleSidebarX(controller: _controller),
body: Row(
children: [
if (!isSmallScreen) ExampleSidebarX(controller: _controller),
Expanded(
child: Center(
child: _ScreensExample(
controller: _controller,
),
),
),
],
),
);
},
),
);
}
}
class ExampleSidebarX extends StatelessWidget {
const ExampleSidebarX({
Key? key,
required SidebarXController controller,
}) : _controller = controller,
super(key: key);
final SidebarXController _controller;
@override
Widget build(BuildContext context) {
return SidebarX(
controller: _controller,
theme: SidebarXTheme(
margin: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: canvasColor,
borderRadius: BorderRadius.circular(20),
),
hoverColor: scaffoldBackgroundColor,
textStyle: TextStyle(color: Colors.white.withOpacity(0.7)),
selectedTextStyle: const TextStyle(color: Colors.white),
itemTextPadding: const EdgeInsets.only(left: 30),
selectedItemTextPadding: const EdgeInsets.only(left: 30),
itemDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(color: canvasColor),
),
selectedItemDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: actionColor.withOpacity(0.37),
),
gradient: const LinearGradient(
colors: [accentCanvasColor, canvasColor],
),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.28),
blurRadius: 30,
)
],
),
iconTheme: IconThemeData(
color: Colors.white.withOpacity(0.7),
size: 20,
),
selectedIconTheme: const IconThemeData(
color: Colors.white,
size: 20,
),
),
extendedTheme: const SidebarXTheme(
width: 200,
decoration: BoxDecoration(
color: canvasColor,
),
),
footerDivider: divider,
headerBuilder: (context, extended) {
return const SizedBox(height: 20);
},
items: const [
SidebarXItem(
icon: Icons.home,
label: 'Raids',
),
SidebarXItem(
icon: Icons.search,
label: 'Disks',
),
],
);
}
}
class _ScreensExample extends StatelessWidget {
const _ScreensExample({
Key? key,
required this.controller,
}) : super(key: key);
final SidebarXController controller;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return AnimatedBuilder(
animation: controller,
builder: (context, child) {
final pageTitle = _getTitleByIndex(controller.selectedIndex);
switch (controller.selectedIndex) {
case 0:
return const RaidPage();
case 1:
return const DiskPage();
default:
return Text(
pageTitle,
style: theme.textTheme.headlineSmall,
);
}
},
);
}
}
String _getTitleByIndex(int index) {
switch (index) {
case 0:
return 'Raids';
case 1:
return 'Disks';
default:
return 'Not found page';
}
}
const primaryColor = Color(0xFF685BFF);
const canvasColor = Color(0xFF232323);
const scaffoldBackgroundColor = Color(0xFF343434);
const accentCanvasColor = Color(0xFF464646);
const white = Colors.white;
final actionColor = const Color(0xFF343434).withOpacity(0.6);
final divider = Divider(color: white.withOpacity(0.3), height: 1);

View File

@ -0,0 +1,62 @@
import 'package:flutter/widgets.dart';
class _BreadCrumbNode {
String name;
Widget widget;
_BreadCrumbNode? next;
_BreadCrumbNode(this.name, this.widget);
}
class BreadCrumbController extends ChangeNotifier {
final Widget defaultRoute;
final String rootName;
late final _BreadCrumbNode _rootPage =
_BreadCrumbNode(rootName, defaultRoute);
late Widget _currentpage = _rootPage.widget;
void pushPage(Widget widget, String name) {
_findPage(null, _rootPage).next = _BreadCrumbNode(name, widget);
_currentpage = widget;
notifyListeners();
}
void switchPage(String name) {
final pageNode = _findPage(name, _rootPage);
_currentpage = pageNode.widget;
// hope for garbage collector to free the floating items (;
pageNode.next = null;
notifyListeners();
}
List<String> getNames() {
return _genNameList(_rootPage);
}
Widget getCurrentPage() {
return _currentpage;
}
_BreadCrumbNode _findPage(String? name, _BreadCrumbNode node) {
if (node.name == name) {
return node;
}
if (node.next != null) {
return _findPage(name, node.next!);
} else {
return node;
}
}
List<String> _genNameList(_BreadCrumbNode node) {
if (node.next != null) {
return _genNameList(node.next!)..insert(0, node.name);
} else {
return [node.name];
}
}
BreadCrumbController(this.defaultRoute, this.rootName);
}

View File

@ -2,75 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_breadcrumb/flutter_breadcrumb.dart';
import 'package:provider/provider.dart';
class _BreadCrumbNode {
String name;
Widget widget;
_BreadCrumbNode? next;
_BreadCrumbNode(this.name, this.widget);
}
class BreadCrumbController extends ChangeNotifier {
final Widget defaultRoute;
final String rootName;
late _BreadCrumbNode _rootPage = _BreadCrumbNode(rootName, defaultRoute);
late Widget _currentpage = _rootPage.widget;
void pushPage(Widget widget, String name) {
_last(_rootPage).next = _BreadCrumbNode(name, widget);
_currentpage = widget;
notifyListeners();
}
void switchPage(String name) {
final pageNode = _findPage(name, _rootPage);
if (pageNode != null) {
_currentpage = pageNode.widget;
// hope for garbage collector to free the floating items (;
pageNode.next = null;
}
notifyListeners();
}
List<String> getNames() {
return _genNameList(_rootPage);
}
Widget getCurrentPage() {
return _currentpage;
}
_BreadCrumbNode _last(_BreadCrumbNode node) {
if (node.next != null) {
return _last(node.next!);
} else {
return node;
}
}
_BreadCrumbNode? _findPage(String name, _BreadCrumbNode node) {
if (node.name == name) {
return node;
}
if (node.next != null) {
return _findPage(name, node.next!);
} else {
return null;
}
}
List<String> _genNameList(_BreadCrumbNode node) {
if (node.next != null) {
return _genNameList(node.next!)..insert(0, node.name);
} else {
return [node.name];
}
}
BreadCrumbController(this.defaultRoute, this.rootName);
}
import '../breadcrumb_controller.dart';
class BreadCrumbPage extends StatefulWidget {
const BreadCrumbPage(
@ -119,7 +51,6 @@ class _BreadCrumbPageState extends State<BreadCrumbPage> {
Consumer<BreadCrumbController>(
builder: (_, value, __) => value.getCurrentPage(),
)
// currentPage
],
),
);

View File

@ -1,10 +1,13 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:raid_manager/api/request.dart';
import 'package:raid_manager/breadcrumb_page.dart';
import 'package:raid_manager/breadcrumb_page/breadcrumb_page.dart';
import 'package:raid_manager/types/disk.dart';
import 'package:raid_manager/utils/disk_info_page.dart';
import 'package:raid_manager/utils/file_formatter.dart';
import 'breadcrumb_controller.dart';
class DiskPage extends StatefulWidget {
const DiskPage({Key? key}) : super(key: key);
@ -56,8 +59,7 @@ class _DiskPageState extends State<DiskPage> {
),
onTap: () {
Provider.of<BreadCrumbController>(context, listen: false)
.pushPage(
const Text("Mysupercool page"), data[idx].name);
.pushPage(const DiskInfoPage(), data[idx].name);
},
);
},

View File

@ -1,205 +1,8 @@
import 'package:flutter/material.dart';
import 'package:raid_manager/disk_page.dart';
import 'package:raid_manager/raid_page.dart';
import 'package:sidebarx/sidebarx.dart';
import 'app.dart';
void main() {
print("starting");
runApp(SidebarXExampleApp());
runApp(App());
}
class SidebarXExampleApp extends StatelessWidget {
SidebarXExampleApp({Key? key}) : super(key: key);
final _controller = SidebarXController(selectedIndex: 0, extended: true);
final _key = GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'SidebarX Example',
theme: ThemeData(
primaryColor: primaryColor,
canvasColor: canvasColor,
scaffoldBackgroundColor: scaffoldBackgroundColor,
textTheme: const TextTheme(
headlineSmall: TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.w800,
),
headlineMedium: TextStyle(
color: Colors.white,
fontSize: 17,
fontWeight: FontWeight.w500,
),
labelMedium: TextStyle(
color: Colors.white,
fontSize: 14,
fontWeight: FontWeight.w200)),
),
home: Builder(
builder: (context) {
final isSmallScreen = MediaQuery.of(context).size.width < 600;
return Scaffold(
key: _key,
appBar: isSmallScreen
? AppBar(
backgroundColor: canvasColor,
title: Text(_getTitleByIndex(_controller.selectedIndex)),
leading: IconButton(
onPressed: () {
// if (!Platform.isAndroid && !Platform.isIOS) {
// _controller.setExtended(true);
// }
_key.currentState?.openDrawer();
},
icon: const Icon(Icons.menu),
),
)
: null,
drawer: ExampleSidebarX(controller: _controller),
body: Row(
children: [
if (!isSmallScreen) ExampleSidebarX(controller: _controller),
Expanded(
child: Center(
child: _ScreensExample(
controller: _controller,
),
),
),
],
),
);
},
),
);
}
}
class ExampleSidebarX extends StatelessWidget {
const ExampleSidebarX({
Key? key,
required SidebarXController controller,
}) : _controller = controller,
super(key: key);
final SidebarXController _controller;
@override
Widget build(BuildContext context) {
return SidebarX(
controller: _controller,
theme: SidebarXTheme(
margin: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: canvasColor,
borderRadius: BorderRadius.circular(20),
),
hoverColor: scaffoldBackgroundColor,
textStyle: TextStyle(color: Colors.white.withOpacity(0.7)),
selectedTextStyle: const TextStyle(color: Colors.white),
itemTextPadding: const EdgeInsets.only(left: 30),
selectedItemTextPadding: const EdgeInsets.only(left: 30),
itemDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(color: canvasColor),
),
selectedItemDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: actionColor.withOpacity(0.37),
),
gradient: const LinearGradient(
colors: [accentCanvasColor, canvasColor],
),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.28),
blurRadius: 30,
)
],
),
iconTheme: IconThemeData(
color: Colors.white.withOpacity(0.7),
size: 20,
),
selectedIconTheme: const IconThemeData(
color: Colors.white,
size: 20,
),
),
extendedTheme: const SidebarXTheme(
width: 200,
decoration: BoxDecoration(
color: canvasColor,
),
),
footerDivider: divider,
headerBuilder: (context, extended) {
return const SizedBox(height: 20);
},
items: const [
SidebarXItem(
icon: Icons.home,
label: 'Raids',
),
SidebarXItem(
icon: Icons.search,
label: 'Disks',
),
],
);
}
}
class _ScreensExample extends StatelessWidget {
const _ScreensExample({
Key? key,
required this.controller,
}) : super(key: key);
final SidebarXController controller;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return AnimatedBuilder(
animation: controller,
builder: (context, child) {
final pageTitle = _getTitleByIndex(controller.selectedIndex);
switch (controller.selectedIndex) {
case 0:
return const RaidPage();
case 1:
return const DiskPage();
default:
return Text(
pageTitle,
style: theme.textTheme.headlineSmall,
);
}
},
);
}
}
String _getTitleByIndex(int index) {
switch (index) {
case 0:
return 'Raids';
case 1:
return 'Disks';
default:
return 'Not found page';
}
}
const primaryColor = Color(0xFF685BFF);
const canvasColor = Color(0xFF232323);
const scaffoldBackgroundColor = Color(0xFF343434);
const accentCanvasColor = Color(0xFF464646);
const white = Colors.white;
final actionColor = const Color(0xFF343434).withOpacity(0.6);
final divider = Divider(color: white.withOpacity(0.3), height: 1);

View File

@ -0,0 +1,28 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../breadcrumb_controller.dart';
class DiskInfoPage extends StatefulWidget {
const DiskInfoPage({Key? key}) : super(key: key);
@override
State<DiskInfoPage> createState() => _DiskInfoPageState();
}
class _DiskInfoPageState extends State<DiskInfoPage> {
@override
Widget build(BuildContext context) {
return Column(
children: [
const Text("Mysupercool page"),
TextButton(
onPressed: () {
Provider.of<BreadCrumbController>(context, listen: false)
.pushPage(const Text("your smart infos..."), "S.M.A.R.T");
},
child: const Text("Click me"))
],
);
}
}