Skip to content
Snippets Groups Projects
viewevents.dart 4.82 KiB
Newer Older
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'datamodel.dart';

class ViewEvents extends StatelessWidget {
Maximilian Betz's avatar
Maximilian Betz committed
  const ViewEvents({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // Get singleton to access locally stored events:
    final EventStoreInstance events = EventStoreInstance();
    return Scaffold(
      appBar: AppBar(
        title: const Text("View Added Events"),
      ),
      body: SingleChildScrollView(
        scrollDirection: Axis.horizontal,
        child: SingleChildScrollView(
          scrollDirection: Axis.vertical,
          child: DataTable(
            columns: const <DataColumn>[
              DataColumn(
                label: Text(
                  'Id',
                  style: TextStyle(fontStyle: FontStyle.italic),
                ),
              ),
              DataColumn(
                label: Text(
                  'URN',
                  style: TextStyle(fontStyle: FontStyle.italic),
                ),
              ),
              DataColumn(
                label: Text(
                  'Label',
                  style: TextStyle(fontStyle: FontStyle.italic),
                ),
              ),
              DataColumn(
                label: Text(
                  'Type',
                  style: TextStyle(fontStyle: FontStyle.italic),
                ),
              ),
              DataColumn(
                label: Text(
                  'Description',
                  style: TextStyle(fontStyle: FontStyle.italic),
                ),
              ),
              DataColumn(
                label: Text(
                  'Latitude',
                  style: TextStyle(fontStyle: FontStyle.italic),
                ),
              ),
              DataColumn(
                label: Text(
                  'Longitude',
                  style: TextStyle(fontStyle: FontStyle.italic),
                ),
              ),
              DataColumn(
                label: Text(
                  'Elevation',
                  style: TextStyle(fontStyle: FontStyle.italic),
                ),
              ),
              DataColumn(
                label: Text(
                  'Status',
                  style: TextStyle(fontStyle: FontStyle.italic),
                ),
              ),
            ],
            rows: <DataRow>[
              for (var event in events.store)
                DataRow(
                  cells: <DataCell>[
                    DataCell(Text(event.id.toString())),
                    DataCell(Text(event.urn)),
                    DataCell(
                      TextFormField(
                        readOnly: true,
                        initialValue: event.label,
                        onFieldSubmitted: (val) {
                          event.label = val; //Update Database
                        },
                      ),
                    ),
                    DataCell(Text(event.type)),
                    DataCell(
                      TextFormField(
                        readOnly: true,
                        initialValue: event.description,
                        onFieldSubmitted: (val) {
                          event.description = val; //Update Database
                        },
                      ),
                    ),
                    DataCell(
                      TextFormField(
                        readOnly: true,
                        initialValue: event.latitude,
                        onFieldSubmitted: (val) {
                          event.latitude = val; //Update Database
                        },
                      ),
                    ),
                    DataCell(
                      TextFormField(
                        readOnly: true,
                        initialValue: event.longitude,
                        onFieldSubmitted: (val) {
                          event.longitude = val; //Update Database
                        },
                      ),
                    ),
                    DataCell(
                      TextFormField(
                        readOnly: true,
                        initialValue: event.elevation,
                        onFieldSubmitted: (val) {
                          event.elevation = val; //Update Database
                        },
                      ),
                    ),
                    DataCell(
                      TextFormField(
                        readOnly: true,
                        initialValue: event.status,
                        onFieldSubmitted: (val) {
                          event.status = val; //Update Database
                        },
}

//TODO: allow editing fields here. Check validation of input value!