Skip to content

Commit

Permalink
add terms popup window
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Ribeaud committed May 1, 2023
1 parent 413a716 commit f0559dd
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions frontend/lib/results.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;

String takeFirst(String text) {
return text.split(" ").first;
}

getTerms(var terms) async {
final response = await http.get(Uri.parse('http://fedlexplorer.openlegallab.ch/term?q=$terms'));
if (response.statusCode == 200) {
var json = jsonDecode(utf8.decode(response.bodyBytes));
return json.length == 0 ? "" : json[0];
}
}

class Item {
Item({
required this.dateApplicability,
Expand Down Expand Up @@ -86,6 +96,29 @@ class _ResultsPageState extends State<ResultsPage> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(item.droit),
ElevatedButton(
onPressed: () async {
String content = await getTerms(item.title);
showDialog<String>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('Terme'),
content: Text(content),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context, 'Cancel'),
child: const Text('Cancel'),
),
TextButton(
onPressed: () => Navigator.pop(context, 'OK'),
child: const Text('OK'),
),
],
),
);
},
child: const Text('Terme'),
)
],
),
),
Expand Down

0 comments on commit f0559dd

Please sign in to comment.