diff --git a/lib/ui/common/notification_provider.dart b/lib/ui/common/notification_provider.dart index 6a010b091b3471c4cf03af603de34ba3bccd5d49..ac695b597f00a30c9c97cf5a6fca70738847943a 100644 --- a/lib/ui/common/notification_provider.dart +++ b/lib/ui/common/notification_provider.dart @@ -1,5 +1,4 @@ import 'dart:async'; - import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; diff --git a/lib/ui/entries/edit_entries.dart b/lib/ui/entries/edit_entries.dart new file mode 100644 index 0000000000000000000000000000000000000000..fe41a2cb50fcaa5a6051e11f01f96cc3d4061380 --- /dev/null +++ b/lib/ui/entries/edit_entries.dart @@ -0,0 +1,160 @@ +import 'package:firebase_auth/firebase_auth.dart'; +import 'package:flutter/material.dart'; +import 'package:firebase_database/firebase_database.dart'; +import 'package:flutter/services.dart'; + +class EditContact extends StatefulWidget { + String diaryKey; + + EditContact({this.diaryKey}); + + @override + _EditContactState createState() => _EditContactState(); +} + +class _EditContactState extends State<EditContact> { + TextEditingController _titleController, _contentController; + String _typeSelected = ''; + + DatabaseReference _ref; + + @override + + void initState() { + // TODO: implement initState + super.initState(); + _titleController = TextEditingController(); + _contentController = TextEditingController(); + _ref = FirebaseDatabase.instance.reference().child('diary'); + getEntryDetail(); + } + @override + Widget build(BuildContext context) { + + void saveContent() { + String title = _titleController.text; + String content = _contentController.text; + String user = FirebaseAuth.instance.currentUser.uid; + Map<String, String> diary = { + 'uid': user, + 'title' : title, + 'content' : content, + 'Timestamp' : DateTime.now().millisecondsSinceEpoch.toString(), + }; + _ref.child(widget.diaryKey).update(diary).then((value) { + Navigator.of(context).pop(); + }); + } + + return Scaffold( + body: SafeArea( + child: Container( + padding: EdgeInsets.only(left: 20, right: 20, bottom: 10), + child: Stack( + children: <Widget>[ + ListView( + children: [ + Theme(data: ThemeData( + highlightColor: Colors.transparent, + splashColor: Colors.transparent, + inputDecorationTheme: InputDecorationTheme(border: InputBorder.none), + ), + child: Form( + child: Column( + children: <Widget>[ + SizedBox(height: 45,), + Padding( + padding: EdgeInsets.only(bottom: 20.0), + child: TextFormField( + controller: _titleController, + keyboardType: TextInputType.multiline, + minLines: 1, + maxLines: 3, + cursorColor: Color(0xFF3C4858), + style: TextStyle(fontWeight: FontWeight.bold), + textAlign: TextAlign.center, + decoration: InputDecoration( + hintText: + // _titleController.text, + 'Please enter today\'s topic', + ), + inputFormatters: [ + LengthLimitingTextInputFormatter(100), + ], + ), + ), + TextFormField( + controller: _contentController, + keyboardType: TextInputType.multiline, + maxLines: null, + cursorColor: Color(0xFF3C4858), + decoration: InputDecoration.collapsed( + hintText: + // _contentController.text), + 'Tell me about it, I don\'t snitch 🤐..'), + ), + ], + ), + ), + ) + + ], + ), + Row( + children: <Widget>[ + InkResponse( + onTap: () { + Navigator.of(context).pop(); + }, + child: Container( + padding: EdgeInsets.all(10), + decoration: BoxDecoration( + color: Colors.white, + border: Border.all(color: Colors.black12), + borderRadius: BorderRadius.circular(100), + boxShadow: [ + BoxShadow( + color: Color(0xFF3C4858).withOpacity(.5), + offset: Offset(1.0, 10.0), + blurRadius: 10.0), + ], + ), + child: Icon( + Icons.arrow_downward, + semanticLabel: 'Back', + size: 22, + ), + )), + ], + ), + ], + ), + ), + ), + floatingActionButton: FloatingActionButton( + backgroundColor: Color(0xFF3C4858), + child: + Icon( + Icons.check, + semanticLabel: 'Save', + ), + onPressed: () { + saveContent(); + }, + ), + ); + } + + getEntryDetail() async{ + DataSnapshot snapshot = await _ref.child(widget.diaryKey).once(); + + Map diary = snapshot.value; + + _titleController.text = diary['title']; + + _contentController.text = diary['content']; + // + // setState(() { + // }); + } +} diff --git a/lib/ui/entries/list_entries.dart b/lib/ui/entries/list_entries.dart index 332080a9679495c160c0cc69b66e53981c1942da..15d8000d4923e4f80c3d9d9e174df886c5c00d83 100644 --- a/lib/ui/entries/list_entries.dart +++ b/lib/ui/entries/list_entries.dart @@ -5,6 +5,7 @@ import 'package:firebase_database/firebase_database.dart'; import 'package:flutter_app/ui/common/slide_up_route.dart'; import 'add_entries.dart'; +import 'edit_entries.dart'; class ListEntries extends StatefulWidget { @@ -22,12 +23,13 @@ class _ListEntriesState extends State<ListEntries> { super.initState(); _ref = FirebaseDatabase.instance .reference() - .child('diary'); + .child('diary') + .orderByChild('Timestamp'); } @override Widget _buildDiaryEntry({Map diary}){ return GestureDetector( - onTap: () => Navigator.of(context).push(SlideUpRoute(widget: AddEntry())), + onTap: () => Navigator.of(context).push(SlideUpRoute(widget: EditContact())), child: Container( margin: EdgeInsets.only(bottom: 15.0, top: 15.0), child: Row( diff --git a/pubspec.lock b/pubspec.lock index dcba042dc0ccd82841a4ce6b7c6ac10ca6d4dc79..b6a9147e9bfe00130a0c4da3148aaf05ac0f6ecb 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -14,14 +14,14 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.5.0-nullsafety.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.0-nullsafety.1" cached_network_image: dependency: "direct dev" description: @@ -35,21 +35,21 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.0-nullsafety.3" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.0-nullsafety.1" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.0-nullsafety.1" cloud_firestore: dependency: "direct main" description: @@ -77,35 +77,35 @@ packages: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0" + version: "1.15.0-nullsafety.3" connectivity: dependency: "direct main" description: name: connectivity url: "https://pub.dartlang.org" source: hosted - version: "3.0.3" + version: "2.0.2" connectivity_for_web: dependency: transitive description: name: connectivity_for_web url: "https://pub.dartlang.org" source: hosted - version: "0.4.0" + version: "0.3.1+4" connectivity_macos: dependency: transitive description: name: connectivity_macos url: "https://pub.dartlang.org" source: hosted - version: "0.2.0" + version: "0.1.0+7" connectivity_platform_interface: dependency: transitive description: name: connectivity_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "1.0.6" convert: dependency: transitive description: @@ -154,7 +154,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.0-nullsafety.1" ffi: dependency: transitive description: @@ -358,21 +358,21 @@ packages: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.3" + version: "0.6.2" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10" + version: "0.12.10-nullsafety.1" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.0-nullsafety.3" octo_image: dependency: transitive description: @@ -386,7 +386,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.0-nullsafety.1" path_provider: dependency: "direct main" description: @@ -524,7 +524,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.0-nullsafety.2" sqflite: dependency: "direct main" description: @@ -545,21 +545,21 @@ packages: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0" + version: "1.10.0-nullsafety.1" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.0-nullsafety.1" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.0-nullsafety.1" synchronized: dependency: transitive description: @@ -573,14 +573,14 @@ packages: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.0-nullsafety.1" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.2.19-nullsafety.2" timezone: dependency: transitive description: @@ -594,7 +594,7 @@ packages: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.0-nullsafety.3" uuid: dependency: transitive description: @@ -608,7 +608,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.0-nullsafety.3" win32: dependency: transitive description: @@ -631,5 +631,5 @@ packages: source: hosted version: "0.1.2" sdks: - dart: ">=2.12.0-259.9.beta <3.0.0" - flutter: ">=1.22.2" + dart: ">=2.10.2 <2.11.0" + flutter: ">=1.22.2 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 2c3b09da198f4ac31d278a0f53296796f3da3b27..5fa2436eb5461d85a4ff7891d8713c6b31567dac 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -44,7 +44,7 @@ dependencies: app_usage: ^1.2.0 flutter_spinkit: "^4.1.2" workmanager: ^0.2.0 - connectivity: ^3.0.3 + connectivity: ^2.0.2 dev_dependencies: