-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add api call for rules, add class for knockout rules
- Loading branch information
Showing
4 changed files
with
152 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:flutter_markdown/flutter_markdown.dart'; | ||
import 'package:knocky/helpers/api.dart'; | ||
import 'package:knocky/models/rule.dart'; | ||
|
||
class ReportPostDialog extends StatefulWidget { | ||
const ReportPostDialog() : super(); | ||
|
||
@override | ||
State<ReportPostDialog> createState() => _ReportPostDialogState(); | ||
} | ||
|
||
const List<String> rules = <String>[]; | ||
|
||
class _ReportPostDialogState extends State<ReportPostDialog> { | ||
String? selectedRule = null; | ||
bool fetchingRules = true; | ||
late List<KnockoutRule>? rules; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
|
||
fetchRules(); | ||
} | ||
|
||
Future<void> fetchRules() async { | ||
List<KnockoutRule>? rulesResult = await KnockoutAPI().rules(); | ||
|
||
setState(() { | ||
fetchingRules = false; | ||
rules = rulesResult; | ||
}); | ||
} | ||
|
||
Widget formContent(BuildContext context) { | ||
return Column( | ||
mainAxisSize: MainAxisSize.max, | ||
children: [ | ||
DropdownButton( | ||
value: selectedRule, | ||
hint: Text('Select rule...'), | ||
items: [ | ||
...rules!.map( | ||
(KnockoutRule rule) => DropdownMenuItem( | ||
child: Text(rule!.title ?? 'N/A'), value: rule!.title), | ||
), | ||
], | ||
onChanged: (String? val) { | ||
setState(() { | ||
selectedRule = val!; | ||
}); | ||
}) | ||
], | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return AlertDialog( | ||
title: Text('Report post'), | ||
content: ConstrainedBox( | ||
constraints: BoxConstraints(maxWidth: 400, minHeight: 100), | ||
child: SizedBox( | ||
width: double.maxFinite, | ||
height: 200, | ||
child: fetchingRules | ||
? Center( | ||
child: Container( | ||
child: CircularProgressIndicator(), | ||
width: 50, | ||
height: 50, | ||
), | ||
) | ||
: formContent(context), | ||
), | ||
), | ||
actions: [ | ||
TextButton( | ||
onPressed: () => Get.back(result: false), child: Text('Cancel')), | ||
ElevatedButton( | ||
onPressed: () => Get.back(result: true), child: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
class KnockoutRule { | ||
int? cardinality; | ||
String? category; | ||
DateTime? createdAt; | ||
String? description; | ||
int? id; | ||
int? rulableId; | ||
String? rulableType; | ||
String? title; | ||
DateTime? updatedAt; | ||
|
||
KnockoutRule({ | ||
this.cardinality, | ||
this.category, | ||
this.createdAt, | ||
this.description, | ||
this.id, | ||
this.rulableId, | ||
this.rulableType, | ||
this.title, | ||
this.updatedAt, | ||
}); | ||
|
||
factory KnockoutRule.fromJson(Map<String, dynamic> json) => KnockoutRule( | ||
cardinality: json["cardinality"] == null ? null : json["cardinality"], | ||
category: json["category"] == null ? null : json["category"], | ||
createdAt: json["createdAt"] == null | ||
? null | ||
: DateTime.parse(json["createdAt"]), | ||
description: json["description"] == null ? null : json["description"], | ||
id: json["id"] == null ? null : json["id"], | ||
title: json["title"] == null ? null : json["title"], | ||
updatedAt: json["updatedAt"] == null | ||
? null | ||
: DateTime.parse(json["updatedAt"]), | ||
); | ||
Map<String, dynamic> toJson() => { | ||
'cardinality': cardinality, | ||
'category': category, | ||
'createdAt': createdAt?.toIso8601String(), | ||
'description': description, | ||
'id': id, | ||
'title': title, | ||
'updatedAt': updatedAt?.toIso8601String(), | ||
}; | ||
} |
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