theming & streamlining a bit.
This commit is contained in:
		@@ -1,6 +1,8 @@
 | 
				
			|||||||
import 'package:date_field/date_field.dart';
 | 
					import 'package:date_field/date_field.dart';
 | 
				
			||||||
 | 
					import 'package:flutter/cupertino.dart';
 | 
				
			||||||
import 'package:flutter/material.dart';
 | 
					import 'package:flutter/material.dart';
 | 
				
			||||||
import 'package:flutter/services.dart';
 | 
					import 'package:flutter/services.dart';
 | 
				
			||||||
 | 
					import 'package:gap/gap.dart';
 | 
				
			||||||
import 'package:nextcloud_reminder/repeating_task.dart';
 | 
					import 'package:nextcloud_reminder/repeating_task.dart';
 | 
				
			||||||
import 'package:nextcloud_reminder/types/repeat.dart';
 | 
					import 'package:nextcloud_reminder/types/repeat.dart';
 | 
				
			||||||
import 'package:nextcloud_reminder/types/tasks.dart';
 | 
					import 'package:nextcloud_reminder/types/tasks.dart';
 | 
				
			||||||
@@ -35,29 +37,60 @@ class _AddTaskWidgetState extends State<AddTaskWidget> {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  String _prettyInterval(DateInterval d) {
 | 
					  String _prettyInterval(DateInterval d) {
 | 
				
			||||||
    switch (d) {
 | 
					    switch (d) {
 | 
				
			||||||
      default:
 | 
					      case DateInterval.daily: return "day";
 | 
				
			||||||
        return d.toString();
 | 
					      case DateInterval.weekly: return "week";
 | 
				
			||||||
 | 
					      case DateInterval.monthly: return "month";
 | 
				
			||||||
 | 
					      case DateInterval.monday: return "monday";
 | 
				
			||||||
 | 
					      case DateInterval.tuesday: return "tuesday";
 | 
				
			||||||
 | 
					      case DateInterval.wednesday: return "wednesday";
 | 
				
			||||||
 | 
					      case DateInterval.thursday: return "thursday";
 | 
				
			||||||
 | 
					      case DateInterval.friday: return "friday";
 | 
				
			||||||
 | 
					      case DateInterval.saturday: return "saturday";
 | 
				
			||||||
 | 
					      case DateInterval.sunday: return "sunday";
 | 
				
			||||||
 | 
					      case DateInterval.dayOfMonth: return "day of the month";
 | 
				
			||||||
 | 
					      case DateInterval.dayOfYear: return "day of the year";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Widget _repeatBuilder(BuildContext context, Tuple2<TextEditingController,ValueNotifier<DateInterval>> data) {
 | 
					  Widget _repeatBuilder(BuildContext context, Tuple2<TextEditingController,ValueNotifier<DateInterval>> data) {
 | 
				
			||||||
    return Row(
 | 
					    return IntrinsicHeight(child: Row(
 | 
				
			||||||
 | 
					      crossAxisAlignment: CrossAxisAlignment.center,
 | 
				
			||||||
      children: [
 | 
					      children: [
 | 
				
			||||||
        Text("Repeat every " ),
 | 
					        SizedBox(
 | 
				
			||||||
        Expanded(
 | 
					          width: 200,
 | 
				
			||||||
          flex: 1,
 | 
					 | 
				
			||||||
          child: TextFormField(
 | 
					          child: TextFormField(
 | 
				
			||||||
            controller: data.item1,
 | 
					            controller: data.item1,
 | 
				
			||||||
            decoration: const InputDecoration(
 | 
					            decoration: InputDecoration(
 | 
				
			||||||
              hintText: "1",
 | 
					              prefix: const Text("Repeat every "),
 | 
				
			||||||
 | 
					              suffix: () {
 | 
				
			||||||
 | 
					                  if (data.item1.value.text.isEmpty) return const Text("");
 | 
				
			||||||
 | 
					                  switch (data.item1.value.text.substring(data.item1.value.text.length - 1)) {
 | 
				
			||||||
 | 
					                    case "1":
 | 
				
			||||||
 | 
					                      return const Text("st");
 | 
				
			||||||
 | 
					                    case "2":
 | 
				
			||||||
 | 
					                      return const Text("nd");
 | 
				
			||||||
 | 
					                    case "3":
 | 
				
			||||||
 | 
					                      return const Text("rd");
 | 
				
			||||||
 | 
					                    default:
 | 
				
			||||||
 | 
					                      return const Text("th");
 | 
				
			||||||
 | 
					              }}(),
 | 
				
			||||||
 | 
					              border: const OutlineInputBorder()
 | 
				
			||||||
            ),
 | 
					            ),
 | 
				
			||||||
 | 
					            textAlign: TextAlign.end,
 | 
				
			||||||
            keyboardType: const TextInputType.numberWithOptions(signed: false, decimal: false),
 | 
					            keyboardType: const TextInputType.numberWithOptions(signed: false, decimal: false),
 | 
				
			||||||
            inputFormatters: [FilteringTextInputFormatter.digitsOnly],
 | 
					            inputFormatters: [FilteringTextInputFormatter.digitsOnly],
 | 
				
			||||||
 | 
					            onChanged: (_) {setState(() {
 | 
				
			||||||
 | 
					              //nothing just rerender.
 | 
				
			||||||
 | 
					            });},
 | 
				
			||||||
          ),
 | 
					          ),
 | 
				
			||||||
        ),
 | 
					        ),
 | 
				
			||||||
 | 
					        const Gap(4),
 | 
				
			||||||
        Expanded(
 | 
					        Expanded(
 | 
				
			||||||
          flex: 3,
 | 
					          //padding: const EdgeInsets.only(left: 30, right: 20),
 | 
				
			||||||
          child: DropdownButton<DateInterval>(
 | 
					          child: DropdownButtonFormField<DateInterval>(
 | 
				
			||||||
 | 
					            decoration: const InputDecoration(
 | 
				
			||||||
 | 
					              border: OutlineInputBorder(),
 | 
				
			||||||
 | 
					            ),
 | 
				
			||||||
            items: DateInterval.values.map((v) => DropdownMenuItem(value: v, child: Text(_prettyInterval(v)))).toList(),
 | 
					            items: DateInterval.values.map((v) => DropdownMenuItem(value: v, child: Text(_prettyInterval(v)))).toList(),
 | 
				
			||||||
            onChanged: (v) => setState(() {
 | 
					            onChanged: (v) => setState(() {
 | 
				
			||||||
              data.item2.value = v ?? data.item2.value;
 | 
					              data.item2.value = v ?? data.item2.value;
 | 
				
			||||||
@@ -65,11 +98,21 @@ class _AddTaskWidgetState extends State<AddTaskWidget> {
 | 
				
			|||||||
            value: data.item2.value,
 | 
					            value: data.item2.value,
 | 
				
			||||||
          ),
 | 
					          ),
 | 
				
			||||||
        ),
 | 
					        ),
 | 
				
			||||||
        IconButton(onPressed: () => setState(() {
 | 
					        PreferredSize(
 | 
				
			||||||
          _repeatEveryController.remove(data);
 | 
					          preferredSize: const Size.square(40),
 | 
				
			||||||
        }), icon: Icon(Icons.remove, color: Theme.of(context).errorColor,)),
 | 
					          child: IconButton(
 | 
				
			||||||
 | 
					          alignment: Alignment.topCenter,
 | 
				
			||||||
 | 
					          onPressed: () => setState(() {
 | 
				
			||||||
 | 
					            _repeatEveryController.remove(data);
 | 
				
			||||||
 | 
					          }),
 | 
				
			||||||
 | 
					          icon: Icon(Icons.remove, color: Theme.of(context).errorColor,)
 | 
				
			||||||
 | 
					        )),
 | 
				
			||||||
      ],
 | 
					      ],
 | 
				
			||||||
    );
 | 
					    ));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Widget _addPadding(Widget w) {
 | 
				
			||||||
 | 
					    return Padding(padding: EdgeInsets.all(4), child: w);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @override
 | 
					  @override
 | 
				
			||||||
@@ -83,7 +126,7 @@ class _AddTaskWidgetState extends State<AddTaskWidget> {
 | 
				
			|||||||
        child: Column(
 | 
					        child: Column(
 | 
				
			||||||
          crossAxisAlignment: CrossAxisAlignment.start,
 | 
					          crossAxisAlignment: CrossAxisAlignment.start,
 | 
				
			||||||
          children: [
 | 
					          children: [
 | 
				
			||||||
            TextFormField(
 | 
					            _addPadding(TextFormField(
 | 
				
			||||||
              // The validator receives the text that the user has entered.
 | 
					              // The validator receives the text that the user has entered.
 | 
				
			||||||
              validator: (value) {
 | 
					              validator: (value) {
 | 
				
			||||||
                if (value == null || value.isEmpty) {
 | 
					                if (value == null || value.isEmpty) {
 | 
				
			||||||
@@ -91,13 +134,14 @@ class _AddTaskWidgetState extends State<AddTaskWidget> {
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
                return null;
 | 
					                return null;
 | 
				
			||||||
              },
 | 
					              },
 | 
				
			||||||
 | 
					              autofocus: true,
 | 
				
			||||||
              controller: _titleController,
 | 
					              controller: _titleController,
 | 
				
			||||||
              decoration: const InputDecoration(
 | 
					              decoration: const InputDecoration(
 | 
				
			||||||
                labelText: "Taskname"
 | 
					                labelText: "Taskname"
 | 
				
			||||||
              ),
 | 
					              ),
 | 
				
			||||||
            ),
 | 
					            )),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            DateTimeField(
 | 
					            _addPadding(DateTimeField(
 | 
				
			||||||
              onDateSelected: (v) => setState(() { _beginDate = v; }),
 | 
					              onDateSelected: (v) => setState(() { _beginDate = v; }),
 | 
				
			||||||
              selectedDate: _beginDate,
 | 
					              selectedDate: _beginDate,
 | 
				
			||||||
              decoration: const InputDecoration(
 | 
					              decoration: const InputDecoration(
 | 
				
			||||||
@@ -105,39 +149,41 @@ class _AddTaskWidgetState extends State<AddTaskWidget> {
 | 
				
			|||||||
                labelText: "Begin"
 | 
					                labelText: "Begin"
 | 
				
			||||||
              ),
 | 
					              ),
 | 
				
			||||||
              mode: DateTimeFieldPickerMode.date,
 | 
					              mode: DateTimeFieldPickerMode.date,
 | 
				
			||||||
            ),
 | 
					            )),
 | 
				
			||||||
            ] + _repeatEveryController.map((c) => _repeatBuilder(context,c)).toList()
 | 
					            ] + _repeatEveryController.map((c) => _addPadding(_repeatBuilder(context,c))).toList()
 | 
				
			||||||
            + [
 | 
					            + [
 | 
				
			||||||
            ElevatedButton(onPressed: () => setState(() {
 | 
					            _addPadding(_addPadding(Row(
 | 
				
			||||||
              _repeatEveryController.add(_emptyRepetition());
 | 
					              children: [
 | 
				
			||||||
            }), child: const Text("add repetition")),
 | 
					                ElevatedButton(onPressed: () => setState(() {
 | 
				
			||||||
            Padding(
 | 
					                  _repeatEveryController.add(_emptyRepetition());
 | 
				
			||||||
              padding: const EdgeInsets.symmetric(vertical: 16.0),
 | 
					                }), child: const Text("add repetition")),
 | 
				
			||||||
              child: ElevatedButton(
 | 
					                Expanded(child: Container()),
 | 
				
			||||||
                onPressed: () {
 | 
					                ElevatedButton(
 | 
				
			||||||
                  // Validate returns true if the form is valid, or false otherwise.
 | 
					                  onPressed: () {
 | 
				
			||||||
                  if (_formKey.currentState!.validate()) {
 | 
					                    // Validate returns true if the form is valid, or false otherwise.
 | 
				
			||||||
                    // If the form is valid, display a snackbar. In the real world,
 | 
					                    if (_formKey.currentState!.validate()) {
 | 
				
			||||||
                    // you'd often call a server or save the information in a database.
 | 
					                      // If the form is valid, display a snackbar. In the real world,
 | 
				
			||||||
                    ScaffoldMessenger.of(context).showSnackBar(
 | 
					                      // you'd often call a server or save the information in a database.
 | 
				
			||||||
                      const SnackBar(content: Text('Task added.')),
 | 
					                      ScaffoldMessenger.of(context).showSnackBar(
 | 
				
			||||||
                    );
 | 
					                        const SnackBar(content: Text('Task added.')),
 | 
				
			||||||
                    var repeats = _repeatEveryController.map((e) => RepeatInterval(interval: e.item2.value, every: int.parse(e.item1.text))).toList();
 | 
					                      );
 | 
				
			||||||
                    var meta = repeats.map((e) => e.toString()).join("/");
 | 
					                      var repeats = _repeatEveryController.map((e) => RepeatInterval(interval: e.item2.value, every: int.parse(e.item1.text))).toList();
 | 
				
			||||||
                    widget.onSave(RepeatingTask(
 | 
					                      var meta = repeats.map((e) => e.toString()).join("/");
 | 
				
			||||||
                      task: TaskExtra(
 | 
					                      widget.onSave(RepeatingTask(
 | 
				
			||||||
                          title: _titleController.text,
 | 
					                        task: TaskExtra(
 | 
				
			||||||
                          begin: _beginDate,
 | 
					                            title: _titleController.text,
 | 
				
			||||||
                          meta: {"repeat": meta},
 | 
					                            begin: _beginDate,
 | 
				
			||||||
                          repeat: repeats,
 | 
					                            meta: {"repeat": meta},
 | 
				
			||||||
                      )
 | 
					                            repeat: repeats,
 | 
				
			||||||
                    ));
 | 
					                        )
 | 
				
			||||||
                    Navigator.pop(context);
 | 
					                      ));
 | 
				
			||||||
                  }
 | 
					                      Navigator.pop(context);
 | 
				
			||||||
                },
 | 
					                    }
 | 
				
			||||||
                child: const Text('Submit'),
 | 
					                  },
 | 
				
			||||||
              ),
 | 
					                  child: const Text('Submit'),
 | 
				
			||||||
            ),
 | 
					                ),
 | 
				
			||||||
 | 
					              ]
 | 
				
			||||||
 | 
					            ))),
 | 
				
			||||||
          ],
 | 
					          ],
 | 
				
			||||||
        ),
 | 
					        ),
 | 
				
			||||||
      )
 | 
					      )
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,7 +16,9 @@ class TodoTxtReminderApp extends StatelessWidget {
 | 
				
			|||||||
      title: 'Nextcloud Reminder',
 | 
					      title: 'Nextcloud Reminder',
 | 
				
			||||||
      theme: ThemeData(
 | 
					      theme: ThemeData(
 | 
				
			||||||
        // This is the theme of your application.
 | 
					        // This is the theme of your application.
 | 
				
			||||||
        primarySwatch: Colors.blue,
 | 
					        primarySwatch: Colors.pink,
 | 
				
			||||||
 | 
					        inputDecorationTheme: const InputDecorationTheme(border: OutlineInputBorder(), ),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      ),
 | 
					      ),
 | 
				
			||||||
      home: const HomeWidget(title: 'todo.txt reminder'),
 | 
					      home: const HomeWidget(title: 'todo.txt reminder'),
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -100,6 +100,13 @@ packages:
 | 
				
			|||||||
      url: "https://pub.dartlang.org"
 | 
					      url: "https://pub.dartlang.org"
 | 
				
			||||||
    source: hosted
 | 
					    source: hosted
 | 
				
			||||||
    version: "0.2.2"
 | 
					    version: "0.2.2"
 | 
				
			||||||
 | 
					  gap:
 | 
				
			||||||
 | 
					    dependency: "direct main"
 | 
				
			||||||
 | 
					    description:
 | 
				
			||||||
 | 
					      name: gap
 | 
				
			||||||
 | 
					      url: "https://pub.dartlang.org"
 | 
				
			||||||
 | 
					    source: hosted
 | 
				
			||||||
 | 
					    version: "2.0.1"
 | 
				
			||||||
  intl:
 | 
					  intl:
 | 
				
			||||||
    dependency: transitive
 | 
					    dependency: transitive
 | 
				
			||||||
    description:
 | 
					    description:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -42,6 +42,7 @@ dependencies:
 | 
				
			|||||||
  flutter_window_close: ^0.2.2
 | 
					  flutter_window_close: ^0.2.2
 | 
				
			||||||
  collection: ^1.16.0
 | 
					  collection: ^1.16.0
 | 
				
			||||||
  date_field: ^3.0.2
 | 
					  date_field: ^3.0.2
 | 
				
			||||||
 | 
					  gap: ^2.0.1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
dev_dependencies:
 | 
					dev_dependencies:
 | 
				
			||||||
  flutter_test:
 | 
					  flutter_test:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user