From 4e7694f653c4fb9cfcd24a86ffb2e6ce4c4201f5 Mon Sep 17 00:00:00 2001 From: lukas-heiligenbrunner Date: Fri, 9 Dec 2022 12:50:58 +0100 Subject: [PATCH] subfolder for breadcrumb page correct title --- app/lib/api/request.dart | 3 +- app/lib/app.dart | 201 +++++++++++++++++ app/lib/breadcrumb_controller.dart | 62 ++++++ .../breadcrumb_page.dart | 71 +----- app/lib/disk_page.dart | 8 +- app/lib/main.dart | 203 +----------------- app/lib/utils/disk_info_page.dart | 28 +++ 7 files changed, 302 insertions(+), 274 deletions(-) create mode 100644 app/lib/app.dart create mode 100644 app/lib/breadcrumb_controller.dart rename app/lib/{ => breadcrumb_page}/breadcrumb_page.dart (54%) create mode 100644 app/lib/utils/disk_info_page.dart diff --git a/app/lib/api/request.dart b/app/lib/api/request.dart index 768d3a5..cff9def 100644 --- a/app/lib/api/request.dart +++ b/app/lib/api/request.dart @@ -3,10 +3,11 @@ import 'dart:convert'; import 'package:flutter/foundation.dart'; import 'package:http/http.dart' as http; -Future> 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); } diff --git a/app/lib/app.dart b/app/lib/app.dart new file mode 100644 index 0000000..513290d --- /dev/null +++ b/app/lib/app.dart @@ -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(); + + @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); diff --git a/app/lib/breadcrumb_controller.dart b/app/lib/breadcrumb_controller.dart new file mode 100644 index 0000000..f64c38d --- /dev/null +++ b/app/lib/breadcrumb_controller.dart @@ -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 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 _genNameList(_BreadCrumbNode node) { + if (node.next != null) { + return _genNameList(node.next!)..insert(0, node.name); + } else { + return [node.name]; + } + } + + BreadCrumbController(this.defaultRoute, this.rootName); +} diff --git a/app/lib/breadcrumb_page.dart b/app/lib/breadcrumb_page/breadcrumb_page.dart similarity index 54% rename from app/lib/breadcrumb_page.dart rename to app/lib/breadcrumb_page/breadcrumb_page.dart index 8fc184a..dcadb61 100644 --- a/app/lib/breadcrumb_page.dart +++ b/app/lib/breadcrumb_page/breadcrumb_page.dart @@ -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 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 _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 { Consumer( builder: (_, value, __) => value.getCurrentPage(), ) - // currentPage ], ), ); diff --git a/app/lib/disk_page.dart b/app/lib/disk_page.dart index ff9eb5a..ac92048 100644 --- a/app/lib/disk_page.dart +++ b/app/lib/disk_page.dart @@ -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 { ), onTap: () { Provider.of(context, listen: false) - .pushPage( - const Text("Mysupercool page"), data[idx].name); + .pushPage(const DiskInfoPage(), data[idx].name); }, ); }, diff --git a/app/lib/main.dart b/app/lib/main.dart index b39b227..eae6088 100644 --- a/app/lib/main.dart +++ b/app/lib/main.dart @@ -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(); - - @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); diff --git a/app/lib/utils/disk_info_page.dart b/app/lib/utils/disk_info_page.dart new file mode 100644 index 0000000..cffd190 --- /dev/null +++ b/app/lib/utils/disk_info_page.dart @@ -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 createState() => _DiskInfoPageState(); +} + +class _DiskInfoPageState extends State { + @override + Widget build(BuildContext context) { + return Column( + children: [ + const Text("Mysupercool page"), + TextButton( + onPressed: () { + Provider.of(context, listen: false) + .pushPage(const Text("your smart infos..."), "S.M.A.R.T"); + }, + child: const Text("Click me")) + ], + ); + } +}