From 1131e74691fcbff7d39fbaa4b4e9f403f6a8326e Mon Sep 17 00:00:00 2001 From: JMARyA Date: Thu, 26 Sep 2024 11:32:55 +0200 Subject: [PATCH] location tree view --- lib/pages/locations.dart | 31 +++++++++++++++++-- pubspec.lock | 64 +++++----------------------------------- pubspec.yaml | 2 +- 3 files changed, 37 insertions(+), 60 deletions(-) diff --git a/lib/pages/locations.dart b/lib/pages/locations.dart index 6b98cf0..b8c4b24 100644 --- a/lib/pages/locations.dart +++ b/lib/pages/locations.dart @@ -1,6 +1,7 @@ import 'package:cdb_ui/api.dart'; import 'package:cdb_ui/pages/transaction.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_simple_treeview/flutter_simple_treeview.dart'; import 'package:qr_bar_code_scanner_dialog/qr_bar_code_scanner_dialog.dart'; class LocationsPage extends StatefulWidget { @@ -25,10 +26,29 @@ class _LocationsPageState extends State { ); } + TreeNode buildTree(BuildContext context, String locID) { + return TreeNode( + key: ValueKey(locID), + content: ListTile( + title: Text(locations![locID]!.name), + onTap: () { + Navigator.of(context).push(MaterialPageRoute( + builder: (context) => LocationView(locations![locID]!), + )); + }, + ), + children: locations!.keys.where((key2) { + if (locations![key2]!.parent != null) { + return locations![key2]!.parent! == locations![locID]!.id; + } + return false; + }).map((key2) { + return buildTree(context, key2); + }).toList()); + } + @override Widget build(BuildContext context) { - // todo : add locations tree view - if (locations == null) { return const Scaffold( body: CircularProgressIndicator(), @@ -39,7 +59,12 @@ class _LocationsPageState extends State { appBar: AppBar( title: const Text("Locations"), ), - body: null, + body: TreeView( + nodes: locations!.keys + .where((key) => locations![key]!.parent == null) + .map((key) { + return buildTree(context, key); + }).toList()), floatingActionButton: FloatingActionButton( onPressed: () { // scan location code diff --git a/pubspec.lock b/pubspec.lock index 18a3532..8ec77fd 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,14 +1,6 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - animated_tree_view: - dependency: "direct main" - description: - name: animated_tree_view - sha256: ed982be7fa2cf51b62bb76e95b6a0f423cde12f1da8745a1da938e82a7baacf2 - url: "https://pub.dev" - source: hosted - version: "2.3.0" async: dependency: transitive description: @@ -49,14 +41,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.18.0" - crypto: - dependency: transitive - description: - name: crypto - sha256: ec30d999af904f33454ba22ed9a86162b35e52b44ac4807d1d93c288041d7d27 - url: "https://pub.dev" - source: hosted - version: "3.0.5" cupertino_icons: dependency: "direct main" description: @@ -65,14 +49,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.8" - diffutil_dart: - dependency: transitive - description: - name: diffutil_dart - sha256: "5e74883aedf87f3b703cb85e815bdc1ed9208b33501556e4a8a5572af9845c81" - url: "https://pub.dev" - source: hosted - version: "4.0.1" equatable: dependency: transitive description: @@ -105,14 +81,6 @@ packages: url: "https://pub.dev" source: hosted version: "7.0.0" - fixnum: - dependency: transitive - description: - name: fixnum - sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1" - url: "https://pub.dev" - source: hosted - version: "1.1.0" fl_chart: dependency: "direct main" description: @@ -134,6 +102,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.3" + flutter_simple_treeview: + dependency: "direct main" + description: + name: flutter_simple_treeview + sha256: ad4978d2668dd078d3a09966832da111bef9102dd636e572c50c80133b7ff4d9 + url: "https://pub.dev" + source: hosted + version: "3.0.2" flutter_test: dependency: "direct dev" description: flutter @@ -304,14 +280,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.1" - scroll_to_index: - dependency: transitive - description: - name: scroll_to_index - sha256: b707546e7500d9f070d63e5acf74fd437ec7eeeb68d3412ef7b0afada0b4f176 - url: "https://pub.dev" - source: hosted - version: "3.0.1" shared_preferences: dependency: "direct main" description: @@ -381,14 +349,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.10.0" - sprintf: - dependency: transitive - description: - name: sprintf - sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23" - url: "https://pub.dev" - source: hosted - version: "7.0.0" stack_trace: dependency: transitive description: @@ -437,14 +397,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.2" - uuid: - dependency: transitive - description: - name: uuid - sha256: f33d6bb662f0e4f79dcd7ada2e6170f3b3a2530c28fc41f49a411ddedd576a77 - url: "https://pub.dev" - source: hosted - version: "4.5.0" vector_math: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index f58703c..c19fe54 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -30,7 +30,7 @@ environment: dependencies: flutter: sdk: flutter - animated_tree_view: ^2.3.0 + flutter_simple_treeview: ^3.0.2 qr_bar_code: ^1.3.0 qr_bar_code_scanner_dialog: ^0.0.5 intl: ^0.18.0