reload files after poping from drawing page
add delete item in top menu bar add feature to rename file by tapping on title bar
This commit is contained in:
		
							
								
								
									
										22
									
								
								lib/app.dart
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								lib/app.dart
									
									
									
									
									
								
							@@ -1,9 +1,7 @@
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:provider/provider.dart';
 | 
			
		||||
 | 
			
		||||
import 'canvas/document_types.dart';
 | 
			
		||||
import 'canvas/drawing_page.dart';
 | 
			
		||||
import 'context/file_change_notifier.dart';
 | 
			
		||||
import 'pages/all_notes_page.dart';
 | 
			
		||||
import 'widgets/collapse_drawer.dart';
 | 
			
		||||
 | 
			
		||||
@@ -19,11 +17,7 @@ class _AppState extends State<App> {
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return ChangeNotifierProvider(
 | 
			
		||||
      create: (ctx) {
 | 
			
		||||
        return FileChangeNotifier()..loadAllNotes();
 | 
			
		||||
      },
 | 
			
		||||
      child: Scaffold(
 | 
			
		||||
    return Scaffold(
 | 
			
		||||
      floatingActionButton: _fab(),
 | 
			
		||||
      body: Row(
 | 
			
		||||
        children: [
 | 
			
		||||
@@ -39,7 +33,6 @@ class _AppState extends State<App> {
 | 
			
		||||
          ))
 | 
			
		||||
        ],
 | 
			
		||||
      ),
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -47,8 +40,7 @@ class _AppState extends State<App> {
 | 
			
		||||
    switch (activePage) {
 | 
			
		||||
      case View.all:
 | 
			
		||||
      case View.folders:
 | 
			
		||||
        return Consumer<FileChangeNotifier>(
 | 
			
		||||
          builder: (ctx, notifier, child) => FloatingActionButton(
 | 
			
		||||
        return FloatingActionButton(
 | 
			
		||||
          onPressed: () async {
 | 
			
		||||
            final now = DateTime.now();
 | 
			
		||||
            final name =
 | 
			
		||||
@@ -56,18 +48,20 @@ class _AppState extends State<App> {
 | 
			
		||||
            final filename = '$name.dbnote';
 | 
			
		||||
 | 
			
		||||
            Navigator.push(
 | 
			
		||||
                ctx,
 | 
			
		||||
              context,
 | 
			
		||||
              MaterialPageRoute(
 | 
			
		||||
                builder: (ctx) => DrawingPage(
 | 
			
		||||
                    meta: NoteMetaData(filename, name, DateTime.now()),
 | 
			
		||||
                  meta: NoteMetaData(
 | 
			
		||||
                      name: name,
 | 
			
		||||
                      relativePath: filename,
 | 
			
		||||
                      lastModified: DateTime.now()),
 | 
			
		||||
                ),
 | 
			
		||||
              ),
 | 
			
		||||
              ).then((v) => notifier.loadAllNotes());
 | 
			
		||||
            );
 | 
			
		||||
          },
 | 
			
		||||
          backgroundColor: const Color(0xff3f3f3f),
 | 
			
		||||
          child: const Icon(Icons.edit_calendar_outlined,
 | 
			
		||||
              color: Color(0xffff7300)),
 | 
			
		||||
          ),
 | 
			
		||||
        );
 | 
			
		||||
      default:
 | 
			
		||||
        return Container();
 | 
			
		||||
 
 | 
			
		||||
@@ -51,5 +51,8 @@ class NoteMetaData {
 | 
			
		||||
  final String relativePath;
 | 
			
		||||
  final DateTime lastModified;
 | 
			
		||||
 | 
			
		||||
  NoteMetaData(this.name, this.relativePath, this.lastModified);
 | 
			
		||||
  NoteMetaData(
 | 
			
		||||
      {required this.name,
 | 
			
		||||
      required this.relativePath,
 | 
			
		||||
      required this.lastModified});
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,9 @@ import 'dart:ui';
 | 
			
		||||
 | 
			
		||||
import 'package:flutter/gestures.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:provider/provider.dart';
 | 
			
		||||
 | 
			
		||||
import '../context/file_change_notifier.dart';
 | 
			
		||||
import '../savesystem/note_file.dart';
 | 
			
		||||
import '../widgets/drawing_page_top_actions.dart';
 | 
			
		||||
import '../widgets/tool_bar.dart';
 | 
			
		||||
@@ -29,6 +31,8 @@ class _DrawingPageState extends State<DrawingPage> {
 | 
			
		||||
 | 
			
		||||
  late PaintController controller;
 | 
			
		||||
  late NoteFile noteFile = NoteFile(widget.meta.relativePath);
 | 
			
		||||
  late TextEditingController titleController =
 | 
			
		||||
      TextEditingController(text: widget.meta.name);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void initState() {
 | 
			
		||||
@@ -45,17 +49,36 @@ class _DrawingPageState extends State<DrawingPage> {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void dispose() {
 | 
			
		||||
  void dispose() async {
 | 
			
		||||
    super.dispose();
 | 
			
		||||
 | 
			
		||||
    noteFile.close();
 | 
			
		||||
    titleController.dispose();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return Scaffold(
 | 
			
		||||
      appBar: AppBar(title: Text(widget.meta.name), actions: [
 | 
			
		||||
        DrawingPageTopActions(controller: controller, noteMetaData: widget.meta)
 | 
			
		||||
    return WillPopScope(
 | 
			
		||||
      onWillPop: () async {
 | 
			
		||||
        await noteFile.close().then((value) =>
 | 
			
		||||
            Provider.of<FileChangeNotifier>(context, listen: false)
 | 
			
		||||
                .loadAllNotes());
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
      },
 | 
			
		||||
      child: Scaffold(
 | 
			
		||||
        appBar: AppBar(
 | 
			
		||||
            title: TextField(
 | 
			
		||||
              onChanged: (value) {
 | 
			
		||||
                noteFile.rename('$value.dbnote');
 | 
			
		||||
              },
 | 
			
		||||
              controller: titleController,
 | 
			
		||||
              style: const TextStyle(color: Colors.white, fontSize: 20),
 | 
			
		||||
              decoration: const InputDecoration(
 | 
			
		||||
                border: InputBorder.none,
 | 
			
		||||
              ),
 | 
			
		||||
            ),
 | 
			
		||||
            actions: [
 | 
			
		||||
              DrawingPageTopActions(
 | 
			
		||||
                  controller: controller, noteMetaData: widget.meta)
 | 
			
		||||
            ]),
 | 
			
		||||
        body: Row(
 | 
			
		||||
          children: [
 | 
			
		||||
@@ -67,6 +90,7 @@ class _DrawingPageState extends State<DrawingPage> {
 | 
			
		||||
            Expanded(child: RepaintBoundary(child: _buildCanvas())),
 | 
			
		||||
          ],
 | 
			
		||||
        ),
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -23,7 +23,8 @@ class FileChangeNotifier extends ChangeNotifier {
 | 
			
		||||
      final lastmodified = (await fsentity.stat()).modified;
 | 
			
		||||
      final filename = fsentity.path.split(Platform.pathSeparator).last;
 | 
			
		||||
      final name = filename.substring(0, filename.length - 7);
 | 
			
		||||
      return NoteMetaData(name, filename, lastmodified);
 | 
			
		||||
      return NoteMetaData(
 | 
			
		||||
          name: name, relativePath: filename, lastModified: lastmodified);
 | 
			
		||||
    }).toList();
 | 
			
		||||
    dta.sort(
 | 
			
		||||
      (a, b) => b.lastModified.compareTo(a.lastModified),
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,12 @@
 | 
			
		||||
import 'package:flutter/foundation.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:permission_handler/permission_handler.dart';
 | 
			
		||||
import 'package:provider/provider.dart';
 | 
			
		||||
import 'package:sqflite/sqflite.dart';
 | 
			
		||||
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
 | 
			
		||||
 | 
			
		||||
import 'app.dart';
 | 
			
		||||
import 'context/file_change_notifier.dart';
 | 
			
		||||
 | 
			
		||||
void main() async {
 | 
			
		||||
  if (defaultTargetPlatform != TargetPlatform.android &&
 | 
			
		||||
@@ -22,8 +24,13 @@ void main() async {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  runApp(MaterialApp(
 | 
			
		||||
  runApp(ChangeNotifierProvider(
 | 
			
		||||
      create: (ctx) {
 | 
			
		||||
        return FileChangeNotifier()..loadAllNotes();
 | 
			
		||||
      },
 | 
			
		||||
      child: MaterialApp(
 | 
			
		||||
        home: const App(),
 | 
			
		||||
    theme: ThemeData(appBarTheme: const AppBarTheme(color: Colors.blueGrey)),
 | 
			
		||||
  ));
 | 
			
		||||
        theme:
 | 
			
		||||
            ThemeData(appBarTheme: const AppBarTheme(color: Colors.blueGrey)),
 | 
			
		||||
      )));
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -7,16 +7,20 @@ import 'path.dart';
 | 
			
		||||
 | 
			
		||||
class NoteFile {
 | 
			
		||||
  late Database _db;
 | 
			
		||||
  String filepath;
 | 
			
		||||
  String filename;
 | 
			
		||||
  late String _basePath;
 | 
			
		||||
 | 
			
		||||
  String? _newFileName;
 | 
			
		||||
 | 
			
		||||
  Database db() {
 | 
			
		||||
    return _db;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  NoteFile(this.filepath);
 | 
			
		||||
  NoteFile(this.filename);
 | 
			
		||||
 | 
			
		||||
  Future<void> init() async {
 | 
			
		||||
    final path = (await getSavePath()).path + Platform.pathSeparator + filepath;
 | 
			
		||||
    _basePath = (await getSavePath()).path;
 | 
			
		||||
    final path = _basePath + Platform.pathSeparator + filename;
 | 
			
		||||
    _db = await openDatabase(
 | 
			
		||||
      path,
 | 
			
		||||
      onCreate: (db, version) async {
 | 
			
		||||
@@ -38,8 +42,13 @@ class NoteFile {
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void delete() {
 | 
			
		||||
    // todo remove db file
 | 
			
		||||
  Future<void> delete() async {
 | 
			
		||||
    await close();
 | 
			
		||||
    await File(_basePath + Platform.pathSeparator + filename).delete();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void rename(String newname) {
 | 
			
		||||
    _newFileName = newname;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Future<void> close() async {
 | 
			
		||||
@@ -50,5 +59,13 @@ class NoteFile {
 | 
			
		||||
    } else {
 | 
			
		||||
      debugPrint('db file unexpectedly closed before shrinking');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // perform qued file renaming operations
 | 
			
		||||
    if (_newFileName != null) {
 | 
			
		||||
      File(_basePath + Platform.pathSeparator + filename)
 | 
			
		||||
          .rename(_basePath + Platform.pathSeparator + _newFileName!);
 | 
			
		||||
      filename = _newFileName!;
 | 
			
		||||
      _newFileName = null;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,12 +3,14 @@ import 'dart:math';
 | 
			
		||||
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:fluttertoast/fluttertoast.dart';
 | 
			
		||||
import 'wip_toast.dart';
 | 
			
		||||
import 'package:provider/provider.dart';
 | 
			
		||||
 | 
			
		||||
import '../canvas/document_types.dart';
 | 
			
		||||
import '../canvas/paint_controller.dart';
 | 
			
		||||
import '../context/file_change_notifier.dart';
 | 
			
		||||
import '../export/export_pdf.dart';
 | 
			
		||||
import 'icon_material_button.dart';
 | 
			
		||||
import 'wip_toast.dart';
 | 
			
		||||
 | 
			
		||||
class DrawingPageTopActions extends StatefulWidget {
 | 
			
		||||
  const DrawingPageTopActions(
 | 
			
		||||
@@ -159,6 +161,20 @@ class _DrawingPageTopActionsState extends State<DrawingPageTopActions> {
 | 
			
		||||
                    );
 | 
			
		||||
                  },
 | 
			
		||||
                ),
 | 
			
		||||
                PopupMenuItem<int>(
 | 
			
		||||
                  value: 0,
 | 
			
		||||
                  child: const Text(
 | 
			
		||||
                    'Delete',
 | 
			
		||||
                    style: TextStyle(color: Color(0xffe5e5e5)),
 | 
			
		||||
                  ),
 | 
			
		||||
                  onTap: () {
 | 
			
		||||
                    widget.controller.file.delete().then((value) {
 | 
			
		||||
                      Provider.of<FileChangeNotifier>(context, listen: false)
 | 
			
		||||
                          .loadAllNotes();
 | 
			
		||||
                      Navigator.of(context).pop();
 | 
			
		||||
                    });
 | 
			
		||||
                  },
 | 
			
		||||
                ),
 | 
			
		||||
              ]);
 | 
			
		||||
        },
 | 
			
		||||
      ),
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,7 @@
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:provider/provider.dart';
 | 
			
		||||
 | 
			
		||||
import '../canvas/document_types.dart';
 | 
			
		||||
import '../canvas/drawing_page.dart';
 | 
			
		||||
import '../context/file_change_notifier.dart';
 | 
			
		||||
 | 
			
		||||
class NoteTile extends StatelessWidget {
 | 
			
		||||
  const NoteTile({Key? key, required this.data}) : super(key: key);
 | 
			
		||||
@@ -19,9 +17,7 @@ class NoteTile extends StatelessWidget {
 | 
			
		||||
          MaterialPageRoute(
 | 
			
		||||
            builder: (context) => DrawingPage(meta: data),
 | 
			
		||||
          ),
 | 
			
		||||
        ).then((value) =>
 | 
			
		||||
            Provider.of<FileChangeNotifier>(context, listen: false)
 | 
			
		||||
                .loadAllNotes());
 | 
			
		||||
        );
 | 
			
		||||
      },
 | 
			
		||||
      child: SizedBox(
 | 
			
		||||
        width: 100,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user