-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: can edit threads (notifier not working still) #298
- Loading branch information
1 parent
eb1304a
commit 64f3e4e
Showing
7 changed files
with
164 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,7 @@ | |
"type": "object", | ||
"required": [ | ||
"kind", | ||
"meeting" | ||
"meeting (optional)" | ||
], | ||
"properties": { | ||
"kind": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:frontend/models/post.dart'; | ||
import 'package:frontend/models/thread.dart'; | ||
import 'package:frontend/services/postService.dart'; | ||
import 'package:frontend/services/threadService.dart'; | ||
|
||
class EditThreadForm extends StatefulWidget { | ||
final Thread? thread; | ||
final Post? post; | ||
EditThreadForm({Key? key, this.thread, this.post}) : super(key: key); | ||
|
||
@override | ||
_EditThreadFormState createState() => _EditThreadFormState(); | ||
} | ||
|
||
class _EditThreadFormState extends State<EditThreadForm> { | ||
final _formKey = GlobalKey<FormState>(); | ||
late TextEditingController _textController; | ||
String kind = 'TEMPLATE'; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_textController = TextEditingController(text: widget.post!.text); | ||
} | ||
|
||
void _submit(BuildContext context) async { | ||
if (_formKey.currentState!.validate()) { | ||
var text = _textController.text; | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar(content: Text('Editing...')), | ||
); | ||
|
||
PostService _postService = PostService(); | ||
ThreadService _threadService = ThreadService(); | ||
|
||
Post? p = await _postService.updatePost(widget.post!.id, text); | ||
Thread? t = | ||
await _threadService.updateThread(id: widget.thread!.id, kind: kind); | ||
|
||
if (p != null && t != null) { | ||
ScaffoldMessenger.of(context).hideCurrentSnackBar(); | ||
|
||
ScaffoldMessenger.of(context).showSnackBar( | ||
SnackBar( | ||
content: Text('Done'), | ||
duration: Duration(seconds: 2), | ||
), | ||
); | ||
|
||
Navigator.pop(context); | ||
} else { | ||
ScaffoldMessenger.of(context).hideCurrentSnackBar(); | ||
|
||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar(content: Text('An error occured.')), | ||
); | ||
|
||
Navigator.pop(context); | ||
} | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
List<String> kinds = ["TEMPLATE", "TO", "FROM", "PHONE_CALL", "MEETING"]; | ||
return Form( | ||
key: _formKey, | ||
child: Column( | ||
children: [ | ||
Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: TextFormField( | ||
keyboardType: TextInputType.multiline, | ||
textInputAction: TextInputAction.newline, | ||
controller: _textController, | ||
validator: (value) { | ||
if (value == null || value.isEmpty) { | ||
return 'Please add the content of communication'; | ||
} | ||
return null; | ||
}, | ||
decoration: const InputDecoration( | ||
icon: const Icon(Icons.work), | ||
labelText: "Content *", | ||
), | ||
), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: DropdownButtonFormField<String>( | ||
icon: Icon(Icons.tag), | ||
items: kinds | ||
.map( | ||
(e) => DropdownMenuItem<String>(value: e, child: Text(e))) | ||
.toList(), | ||
value: kinds[0], | ||
selectedItemBuilder: (BuildContext context) { | ||
return kinds.map((e) { | ||
return Align( | ||
alignment: AlignmentDirectional.centerStart, | ||
child: Container(child: Text(e)), | ||
); | ||
}).toList(); | ||
}, | ||
onChanged: (next) { | ||
setState(() { | ||
kind = next!; | ||
}); | ||
}, | ||
), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: ElevatedButton( | ||
onPressed: () => _submit(context), | ||
child: const Text('Submit'), | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters