Skip to content

Commit

Permalink
Merge branch 'main' of github.com:ribeaud/fedlexplorer
Browse files Browse the repository at this point in the history
  • Loading branch information
loleg committed Apr 30, 2023
2 parents 453ac98 + 46b48a1 commit dfca590
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 21 deletions.
56 changes: 38 additions & 18 deletions frontend/lib/main.dart
Expand Up @@ -17,10 +17,6 @@ class MainApp extends StatelessWidget {
title: appTitle,
home: Scaffold(
appBar: AppBar(
leading: IconButton(
onPressed: () {},
icon: Icon(Icons.home),
),
title: const Text(appTitle),
),
body: const FedlexForm(),
Expand All @@ -40,11 +36,12 @@ class FedlexForm extends StatefulWidget {

class FedlexFormState extends State<FedlexForm> {
final _formKey = GlobalKey<FormState>();
final fromController = TextEditingController();

getData() async {
final response = await http.get(Uri.parse('http://fedlexplorer.openlegallab.ch/sample'));
getData(var from) async {
final response = await http.get(Uri.parse('http://fedlexplorer.openlegallab.ch/sample?from=$from'));
if (response.statusCode == 200) {
return jsonDecode(response.body);
return jsonDecode(utf8.decode(response.bodyBytes));
}
}

Expand All @@ -56,27 +53,50 @@ class FedlexFormState extends State<FedlexForm> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextFormField(
// The validator receives the text that the user has entered.
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter some text';
}
return null;
},
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: TextFormField(
// The validator receives the text that the user has entered.
validator: (value) {
if (value == null || value.isEmpty) {
return 'Bitte ein Datum eingeben (JJJJ-MM-TT)';
}
return null;
},
controller: fromController,
decoration: const InputDecoration(
label: Text.rich(
TextSpan(
children: <InlineSpan>[
WidgetSpan(
child: Text(
'Inkrafttreten von',
),
),
WidgetSpan(
child: Text(
'*',
style: TextStyle(color: Colors.red),
),
),
],
),
),
),
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 16.0),
child: ElevatedButton(
onPressed: () async {
if (_formKey.currentState!.validate()) {
var data = await getData();
var data = await getData(fromController.text);
Navigator.push(context, MaterialPageRoute(builder: (context) {
return ResultsPage(data: data);
}));
}
},
child: const Text('Submit'),
child: const Text('Zeigen'),
),
),
],
Expand Down
18 changes: 15 additions & 3 deletions frontend/lib/results.dart
Expand Up @@ -4,14 +4,23 @@ class Item {
Item({
required this.dateApplicability,
required this.title,
required this.rs,
required this.droit,
this.isExpanded = false,
});

String dateApplicability;
String title;
String rs;
String droit;
bool isExpanded;

static Item fromJson(json) => Item(title: json['title'], dateApplicability: json['dateApplicability']);
static Item fromJson(json) => Item(
title: json['title'],
dateApplicability: json['dateApplicability'],
rs: json['rs'],
droit: json['droit'],
);
}

List<Item> generateItems(data) {
Expand Down Expand Up @@ -59,10 +68,13 @@ class _ResultsPageState extends State<ResultsPage> {
return ExpansionPanel(
headerBuilder: (BuildContext context, bool isExpanded) {
return ListTile(
title: Text(item.dateApplicability),
title: Text(item.title),
);
},
body: ListTile(title: Text(item.title)),
body: ListTile(
title: Text(item.dateApplicability),
subtitle: Text("${item.dateApplicability}, ${item.rs}, ${item.droit}"),
),
isExpanded: item.isExpanded,
);
}).toList(),
Expand Down

0 comments on commit dfca590

Please sign in to comment.