166 lines
5.7 KiB
Dart
166 lines
5.7 KiB
Dart
import 'package:firebase_auth/firebase_auth.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
import 'package:intl/intl.dart';
|
|
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
|
|
import 'package:tasktracker/NewJournal.dart';
|
|
import 'package:tasktracker/main.dart';
|
|
import 'User.dart' as User;
|
|
import 'Dialogs.dart';
|
|
|
|
class JournalPage extends StatefulWidget {
|
|
const JournalPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<JournalPage> createState() => _JournalPageState();
|
|
}
|
|
|
|
class _JournalPageState extends State<JournalPage> {
|
|
|
|
bool selecting = false;
|
|
List<int> selectedIndexes = [];
|
|
var refreshStream;
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
super.initState();
|
|
|
|
refreshStream = User.refreshStream.stream.listen((event) {if(!event){setState(() {
|
|
|
|
});}});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
// TODO: implement dispose
|
|
super.dispose();
|
|
refreshStream?.close();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
floatingActionButton: FloatingActionButton.extended(
|
|
onPressed: () {
|
|
Navigator.of(context).push(MaterialPageRoute(builder: (context) => NewJournal())).then((val) {
|
|
setState(() {});
|
|
});
|
|
},
|
|
label: Text("New Entry"),
|
|
icon: Icon(Icons.add)),
|
|
appBar: AppBar(
|
|
title: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
FaIcon(FontAwesomeIcons.bookJournalWhills),
|
|
SizedBox(
|
|
width: 15,
|
|
),
|
|
Text('Journal')
|
|
],
|
|
),
|
|
Row(
|
|
children: [
|
|
if(selecting && selectedIndexes.length > 0)InkWell(onTap:() async{
|
|
selecting=false;
|
|
for (int element in selectedIndexes) {
|
|
await User.UserOperations.deleteJournal(User.journal[element].id);
|
|
}setState(() {
|
|
|
|
});
|
|
},child: Container(margin:EdgeInsets.all(8),child: Icon(Icons.delete))),
|
|
if(selecting)InkWell(onTap:(){
|
|
selecting=false;
|
|
setState(() {
|
|
|
|
});
|
|
},child: Container(margin:EdgeInsets.all(8),child: Icon(Icons.cancel))),
|
|
],
|
|
)
|
|
],
|
|
),
|
|
),
|
|
drawer: navDrawer(context, 8),
|
|
body: Container(
|
|
padding: EdgeInsets.all(8),
|
|
child: ScrollablePositionedList.builder(
|
|
itemCount: User.journal.length,
|
|
itemBuilder: (context, index) {
|
|
return Container(
|
|
|
|
//duration: Duration(milliseconds: 500),
|
|
child: InkWell(
|
|
onTap: (){
|
|
if(selecting){
|
|
if(selectedIndexes.contains(index)){
|
|
selectedIndexes.remove(index);
|
|
}else{
|
|
selectedIndexes.add(index);
|
|
}
|
|
setState(() {
|
|
|
|
});
|
|
}
|
|
},
|
|
onLongPress: () {
|
|
selecting = !selecting;
|
|
if(!selectedIndexes.contains(index)){selectedIndexes.add(index);}
|
|
setState(() {});
|
|
},
|
|
child: Row(
|
|
children: [
|
|
if (selecting)
|
|
Checkbox(
|
|
value: selectedIndexes.contains(index),
|
|
onChanged: (newVal) {
|
|
if(selectedIndexes.contains(index)){
|
|
selectedIndexes.remove(index);
|
|
}else{
|
|
selectedIndexes.add(index);
|
|
}
|
|
setState(() {
|
|
|
|
});
|
|
},
|
|
),
|
|
Expanded(
|
|
child: Card(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(User.journal[index].title ?? '', style: TextStyle(fontSize: 18)),
|
|
Text(DateFormat('yyyy-MM-dd').format(User.journal[index].day))
|
|
],
|
|
),
|
|
if (User.journal[index].description != null && User.journal[index].description!.isNotEmpty)
|
|
Text(User.journal[index].description!)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
if(selecting)InkWell(onTap:(){
|
|
Navigator.of(context).push(MaterialPageRoute(builder: (context) => NewJournal(date: User.journal[index].day, title: User.journal[index].title, text: User.journal[index].description,))).then((val) {
|
|
setState(() {});
|
|
});
|
|
selecting=false;
|
|
setState(() {
|
|
|
|
});
|
|
},child: Container(margin:EdgeInsets.all(8),child: FaIcon(FontAwesomeIcons.edit)))
|
|
],
|
|
),
|
|
));
|
|
}),
|
|
),
|
|
);
|
|
}
|
|
}
|