From 84eef419968da12fb1f37598ec738fc65ae3d86f Mon Sep 17 00:00:00 2001 From: lukas-heiligenbrunner Date: Sun, 30 Oct 2022 21:57:13 +0100 Subject: [PATCH] display filename on top bar rearrange some imports add linter rules --- analysis_options.yaml | 11 ++++- lib/app.dart | 12 +++-- lib/canvas/document_types.dart | 1 + lib/canvas/drawing_page.dart | 80 +++++++++++++++++--------------- lib/canvas/my_painter.dart | 5 +- lib/canvas/paint_controller.dart | 1 + lib/pages/all_notes_page.dart | 7 +-- lib/savesystem/line_loader.dart | 2 +- lib/savesystem/note_file.dart | 3 +- lib/widgets/collapse_drawer.dart | 5 +- lib/widgets/note_tile.dart | 3 +- 11 files changed, 78 insertions(+), 52 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 39d6341..56063e0 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -22,8 +22,17 @@ linter: # `// ignore_for_file: name_of_lint` syntax on the line or in the file # producing the lint. rules: - avoid_print: false # Uncomment to disable the `avoid_print` rule + avoid_print: true # Uncomment to disable the `avoid_print` rule prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + prefer_relative_imports: true + avoid_empty_else: true + avoid_returning_null_for_future: true + avoid_web_libraries_in_flutter: true + collection_methods_unrelated_type: true + comment_references: true + control_flow_in_finally: true + empty_statements: true + unnecessary_null_checks: true # Additional information about this file can be found at # https://dart.dev/guides/language/analysis-options diff --git a/lib/app.dart b/lib/app.dart index bd5cf91..c8dad00 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:notes/context/file_change_notifier.dart'; import 'package:provider/provider.dart'; import 'canvas/drawing_page.dart'; +import 'context/file_change_notifier.dart'; import 'pages/all_notes_page.dart'; import 'widgets/collapse_drawer.dart'; @@ -51,13 +51,17 @@ class _AppState extends State { return FloatingActionButton( onPressed: () async { final now = DateTime.now(); - String filename = - 'note-${now.year}_${now.month}_${now.day}-${now.hour}_${now.minute}.dbnote'; + final name = + 'note-${now.year}_${now.month}_${now.day}-${now.hour}_${now.minute}'; + final filename = '$name.dbnote'; Navigator.push( context, MaterialPageRoute( - builder: (ctx) => DrawingPage(filePath: filename), + builder: (ctx) => DrawingPage( + filePath: filename, + name: name, + ), ), ).then((value) => Provider.of(context, listen: false) diff --git a/lib/canvas/document_types.dart b/lib/canvas/document_types.dart index a5dd561..3ff5318 100644 --- a/lib/canvas/document_types.dart +++ b/lib/canvas/document_types.dart @@ -35,6 +35,7 @@ class Stroke { } Stroke.fromPoints(this.points, this.id, this.color); + Stroke(this.id, this.color); } diff --git a/lib/canvas/drawing_page.dart b/lib/canvas/drawing_page.dart index 91ff6d6..e1765ba 100644 --- a/lib/canvas/drawing_page.dart +++ b/lib/canvas/drawing_page.dart @@ -1,22 +1,25 @@ import 'dart:math'; import 'dart:ui'; + import 'package:fluentui_system_icons/fluentui_system_icons.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; -import 'package:notes/savesystem/note_file.dart'; + +import '../savesystem/note_file.dart'; +import '../widgets/icon_material_button.dart'; +import '../widgets/tool_bar.dart'; import 'my_painter.dart'; import 'paint_controller.dart'; import 'screen_document_mapping.dart'; -import '../widgets/icon_material_button.dart'; -import '../widgets/tool_bar.dart'; - /// Handles input events and draws canvas element class DrawingPage extends StatefulWidget { // path to the .dbnote file final String filePath; + final String name; - const DrawingPage({Key? key, required this.filePath}) : super(key: key); + const DrawingPage({Key? key, required this.filePath, required this.name}) + : super(key: key); @override State createState() => _DrawingPageState(); @@ -53,37 +56,40 @@ class _DrawingPageState extends State { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar(backgroundColor: Colors.blueGrey, actions: [ - IconMaterialButton( - icon: const Icon(FluentIcons.book_open_48_filled), - color: const Color.fromRGBO(255, 255, 255, .85), - onPressed: () { - // todo implement - }, - ), - IconMaterialButton( - icon: const Icon(FluentIcons.document_one_page_24_regular), - color: const Color.fromRGBO(255, 255, 255, .85), - onPressed: () { - // todo implement - }, - ), - IconMaterialButton( - icon: const Icon(Icons.attachment_outlined), - color: const Color.fromRGBO(255, 255, 255, .85), - onPressed: () { - // todo implement - }, - rotation: -pi / 4, - ), - IconMaterialButton( - icon: const Icon(Icons.more_vert), - color: const Color.fromRGBO(255, 255, 255, .85), - onPressed: () { - // todo implement - }, - ), - ]), + appBar: AppBar( + backgroundColor: Colors.blueGrey, + title: Text(widget.name), + actions: [ + IconMaterialButton( + icon: const Icon(FluentIcons.book_open_48_filled), + color: const Color.fromRGBO(255, 255, 255, .85), + onPressed: () { + // todo implement + }, + ), + IconMaterialButton( + icon: const Icon(FluentIcons.document_one_page_24_regular), + color: const Color.fromRGBO(255, 255, 255, .85), + onPressed: () { + // todo implement + }, + ), + IconMaterialButton( + icon: const Icon(Icons.attachment_outlined), + color: const Color.fromRGBO(255, 255, 255, .85), + onPressed: () { + // todo implement + }, + rotation: -pi / 4, + ), + IconMaterialButton( + icon: const Icon(Icons.more_vert), + color: const Color.fromRGBO(255, 255, 255, .85), + onPressed: () { + // todo implement + }, + ), + ]), body: Row( children: [ ToolBar( @@ -110,7 +116,7 @@ class _DrawingPageState extends State { setState(() { offset = Offset((-canvasWidth * zoom) + canvasWidth, newOffset.dy); }); - print(offset); + debugPrint(offset.toString()); } else { setState(() { offset = offset + delta; diff --git a/lib/canvas/my_painter.dart b/lib/canvas/my_painter.dart index f0c29db..3bbc1d9 100644 --- a/lib/canvas/my_painter.dart +++ b/lib/canvas/my_painter.dart @@ -1,8 +1,9 @@ import 'dart:math'; import 'package:flutter/material.dart'; -import 'package:notes/canvas/paint_controller.dart'; -import 'package:notes/canvas/screen_document_mapping.dart'; + +import 'paint_controller.dart'; +import 'screen_document_mapping.dart'; final Rect a4Page = Rect.fromPoints(const Offset(.0, .0), const Offset(210, 210 * sqrt2)); diff --git a/lib/canvas/paint_controller.dart b/lib/canvas/paint_controller.dart index bd295b7..d235e40 100644 --- a/lib/canvas/paint_controller.dart +++ b/lib/canvas/paint_controller.dart @@ -1,5 +1,6 @@ import 'dart:math'; import 'dart:ui'; + import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; diff --git a/lib/pages/all_notes_page.dart b/lib/pages/all_notes_page.dart index ab9e43f..82739ea 100644 --- a/lib/pages/all_notes_page.dart +++ b/lib/pages/all_notes_page.dart @@ -1,9 +1,10 @@ import 'package:flutter/material.dart'; -import 'package:notes/context/file_change_notifier.dart'; -import 'package:notes/widgets/icon_material_button.dart'; -import 'package:notes/widgets/note_tile.dart'; import 'package:provider/provider.dart'; +import '../context/file_change_notifier.dart'; +import '../widgets/icon_material_button.dart'; +import '../widgets/note_tile.dart'; + class AllNotesPage extends StatefulWidget { const AllNotesPage({Key? key}) : super(key: key); diff --git a/lib/savesystem/line_loader.dart b/lib/savesystem/line_loader.dart index bb20e75..34205f6 100644 --- a/lib/savesystem/line_loader.dart +++ b/lib/savesystem/line_loader.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; -import 'note_file.dart'; import '../canvas/document_types.dart'; +import 'note_file.dart'; extension LineLoading on NoteFile { Future> loadStrokes() async { diff --git a/lib/savesystem/note_file.dart b/lib/savesystem/note_file.dart index 98f3352..e80fb62 100644 --- a/lib/savesystem/note_file.dart +++ b/lib/savesystem/note_file.dart @@ -1,8 +1,9 @@ import 'dart:io'; -import 'package:notes/savesystem/path.dart'; import 'package:sqflite/sqflite.dart'; +import 'path.dart'; + class NoteFile { late Database _db; String filepath; diff --git a/lib/widgets/collapse_drawer.dart b/lib/widgets/collapse_drawer.dart index 3d77ff1..c4785cd 100644 --- a/lib/widgets/collapse_drawer.dart +++ b/lib/widgets/collapse_drawer.dart @@ -1,9 +1,10 @@ import 'package:fluentui_system_icons/fluentui_system_icons.dart'; import 'package:flutter/material.dart'; -import 'package:notes/context/file_change_notifier.dart'; -import 'package:notes/widgets/drawer_item.dart'; import 'package:provider/provider.dart'; +import '../context/file_change_notifier.dart'; +import 'drawer_item.dart'; + enum View { all, shared, recycle, folders } class CollapseDrawer extends StatefulWidget { diff --git a/lib/widgets/note_tile.dart b/lib/widgets/note_tile.dart index ef12e5d..e10e473 100644 --- a/lib/widgets/note_tile.dart +++ b/lib/widgets/note_tile.dart @@ -24,7 +24,8 @@ class NoteTile extends StatelessWidget { Navigator.push( context, MaterialPageRoute( - builder: (context) => DrawingPage(filePath: data.relativePath), + builder: (context) => + DrawingPage(filePath: data.relativePath, name: data.name), ), ).then((value) => Provider.of(context, listen: false)