reload files view when adding/editing a note

organize in folders
This commit is contained in:
2022-10-29 22:55:38 +02:00
parent 7baef13eae
commit ab1bacea00
13 changed files with 182 additions and 156 deletions

View File

@ -0,0 +1,136 @@
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';
enum View { all, shared, recycle, folders }
class CollapseDrawer extends StatefulWidget {
const CollapseDrawer(
{Key? key, required this.onPageChange, required this.activePage})
: super(key: key);
final void Function(View newPage) onPageChange;
final View activePage;
@override
State<CollapseDrawer> createState() => _CollapseDrawerState();
}
class _CollapseDrawerState extends State<CollapseDrawer>
with SingleTickerProviderStateMixin {
bool collapsed = true;
late Animation collapseAnimation;
late AnimationController controller;
@override
void initState() {
super.initState();
controller = AnimationController(
vsync: this, duration: const Duration(milliseconds: 200));
collapseAnimation = Tween<double>(begin: 62, end: 300).animate(controller)
..addListener(() {
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.only(top: MediaQuery.of(context).viewPadding.top),
color: const Color(0xff0d0d0d),
child: ClipRRect(
borderRadius: const BorderRadius.only(
topRight: Radius.circular(10), bottomRight: Radius.circular(10)),
child: Container(
color: const Color(0xff3f3f3f),
child: ConstrainedBox(
constraints: BoxConstraints.expand(width: collapseAnimation.value),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
const SizedBox(
height: 10,
),
Row(
children: [
const SizedBox(
width: 8,
),
Material(
color: Colors.transparent,
shape: const CircleBorder(),
clipBehavior: Clip.hardEdge,
child: IconButton(
icon: const Icon(Icons.menu),
iconSize: 28,
color: const Color(0xffcfcfcf),
onPressed: () {
collapsed
? controller.forward()
: controller.reverse();
setState(() => collapsed = !collapsed);
},
),
),
if (!collapsed) ...[
const Expanded(child: SizedBox()),
Material(
color: Colors.transparent,
shape: const CircleBorder(),
clipBehavior: Clip.hardEdge,
child: IconButton(
icon: const Icon(Icons.settings_outlined),
iconSize: 26,
color: const Color(0xffa8a8a8),
onPressed: () {},
),
),
const SizedBox(
width: 15,
)
]
],
),
const SizedBox(
height: 40,
),
Expanded(
child: ListView(
children: [
Consumer<FileChangeNotifier>(
builder: (context, value, child) => DrawerItem(
dta: ItemData('All Notes', Icons.book),
collapsed: collapsed,
endText: value.tiledata.length.toString(),
active: widget.activePage == View.all,
onTap: () => widget.onPageChange(View.all)),
),
DrawerItem(
dta: ItemData('Shared Notebooks', Icons.person_outline),
collapsed: collapsed,
active: widget.activePage == View.shared,
onTap: () => widget.onPageChange(View.shared)),
DrawerItem(
dta: ItemData(
'Recycle bin', FluentIcons.delete_20_filled),
collapsed: collapsed,
active: widget.activePage == View.recycle,
onTap: () => widget.onPageChange(View.recycle)),
DrawerItem(
dta: ItemData('Folders', Icons.folder_outlined),
collapsed: collapsed,
active: widget.activePage == View.folders,
onTap: () => widget.onPageChange(View.folders)),
],
)),
],
),
),
),
),
);
}
}

View File

@ -0,0 +1,75 @@
import 'package:flutter/material.dart';
class DrawerItem extends StatelessWidget {
const DrawerItem(
{Key? key,
required this.dta,
this.endText,
required this.collapsed,
required this.active,
required this.onTap})
: super(key: key);
final ItemData dta;
final String? endText;
final bool collapsed;
final bool active;
final void Function() onTap;
@override
Widget build(BuildContext context) {
return InkWell(
onTap: onTap,
child: Padding(
padding: const EdgeInsets.only(left: 9, top: 7, bottom: 7, right: 9),
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
color: active ? const Color(0xff6e6e6e) : Colors.transparent,
child: Padding(
padding:
const EdgeInsets.only(left: 9, top: 7, bottom: 7, right: 9),
child: Row(
children: [
Icon(
dta.icon,
size: 26,
color: const Color(0xffdbdbdb),
),
if (!collapsed) ...[
const SizedBox(
width: 10,
),
Text(
dta.name,
style: const TextStyle(color: Color(0xffe9e9e9)),
),
Expanded(child: Container()),
Text(
endText ?? '',
style: const TextStyle(color: Color(0xffafafaf)),
),
const SizedBox(
width: 15,
)
]
],
),
),
),
),
),
);
}
}
class ItemData {
String name;
IconData icon;
ItemData(this.name, this.icon);
@override
String toString() {
return 'ItemData{name: $name, icon: $icon}';
}
}

View File

@ -0,0 +1,44 @@
import 'package:flutter/material.dart';
class IconMaterialButton extends StatelessWidget {
const IconMaterialButton(
{Key? key,
required this.icon,
required this.color,
required this.onPressed,
this.selected,
this.iconSize,
this.rotation})
: super(key: key);
final Widget icon;
final Color color;
final void Function() onPressed;
final bool? selected;
final double? iconSize;
final double? rotation;
@override
Widget build(BuildContext context) {
return Material(
color: selected ?? false ? const Color(0xff6e6e6e) : Colors.transparent,
shape: const CircleBorder(),
clipBehavior: Clip.hardEdge,
child: IconButton(
icon: _buildIcon(),
iconSize: iconSize ?? 28,
color: color,
onPressed: onPressed,
),
);
}
Widget _buildIcon() {
return rotation == null
? icon
: Transform.rotate(
angle: rotation!,
child: icon,
);
}
}

View File

@ -0,0 +1,56 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../canvas/drawing_page.dart';
import '../context/file_change_notifier.dart';
class NoteTileData {
final String name;
final String relativePath;
final DateTime lastModified;
NoteTileData(this.name, this.relativePath, this.lastModified);
}
class NoteTile extends StatelessWidget {
const NoteTile({Key? key, required this.data}) : super(key: key);
final NoteTileData data;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DrawingPage(filePath: data.relativePath),
),
).then((value) =>
Provider.of<FileChangeNotifier>(context, listen: false)
.loadAllNotes());
},
child: SizedBox(
width: 100,
child: Column(
children: [
SizedBox(
height: 150,
width: 100,
child: Container(
color: Colors.white,
),
),
Text(
data.name,
style: const TextStyle(color: Colors.white),
overflow: TextOverflow.ellipsis,
),
Text('${data.lastModified.hour}:${data.lastModified.minute}',
style: const TextStyle(color: Colors.white))
],
),
),
);
}
}

86
lib/widgets/tool_bar.dart Normal file
View File

@ -0,0 +1,86 @@
import 'package:adwaita_icons/adwaita_icons.dart';
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
import 'package:flutter/material.dart';
import 'package:iconify_flutter/iconify_flutter.dart';
import 'package:iconify_flutter/icons/emojione_monotone.dart';
import 'package:iconify_flutter/icons/jam.dart';
import '../canvas/paint_controller.dart';
import 'icon_material_button.dart';
class ToolBar extends StatefulWidget {
const ToolBar({Key? key, required this.onPenChange}) : super(key: key);
final void Function(Pen pen) onPenChange;
@override
State<ToolBar> createState() => _ToolBarState();
}
class _ToolBarState extends State<ToolBar> {
Pen activepen = Pen.pen;
@override
Widget build(BuildContext context) {
return Container(
color: const Color(0xff3f3f3f),
width: 45,
child: Column(
children: [
const SizedBox(
height: 10,
),
IconMaterialButton(
icon: const Iconify(
EmojioneMonotone.fountain_pen,
color: Color.fromRGBO(255, 255, 255, .85),
),
color: const Color.fromRGBO(255, 255, 255, .85),
onPressed: () {
setState(() => activepen = Pen.pen);
widget.onPenChange(Pen.pen);
},
selected: activepen == Pen.pen,
iconSize: 24,
),
IconMaterialButton(
icon: const Iconify(
Jam.highlighter,
color: Color.fromRGBO(255, 255, 255, .85),
),
color: const Color.fromRGBO(255, 255, 255, .85),
onPressed: () {
setState(() => activepen = Pen.highlighter);
widget.onPenChange(Pen.highlighter);
},
selected: activepen == Pen.highlighter,
iconSize: 24,
),
IconMaterialButton(
icon: Transform.translate(
offset: const Offset(-2.0, .0),
child: const AdwaitaIcon(AdwaitaIcons.eraser2),
),
color: const Color.fromRGBO(255, 255, 255, .85),
onPressed: () {
setState(() => activepen = Pen.eraser);
widget.onPenChange(Pen.eraser);
},
iconSize: 24,
selected: activepen == Pen.eraser,
),
IconMaterialButton(
icon: const Icon(FluentIcons.select_object_24_regular),
color: const Color.fromRGBO(255, 255, 255, .85),
onPressed: () {
setState(() => activepen = Pen.selector);
widget.onPenChange(Pen.selector);
},
selected: activepen == Pen.selector,
iconSize: 24,
),
],
),
);
}
}