first steps

This commit is contained in:
Nicole Dresselhaus 2023-01-07 22:23:59 +01:00
parent 25da5f1ba4
commit 0cfed3e321
4 changed files with 154 additions and 33 deletions

View File

@ -1,4 +1,6 @@
import 'package:flutter/material.dart';
import 'package:nextcloud_reminder/repeating_task.dart';
import 'package:nextcloud_reminder/table.dart';
void main() {
runApp(const MyApp());
@ -24,7 +26,7 @@ class MyApp extends StatelessWidget {
// is not restarted.
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
home: const MyHomePage(title: 'todo.txt reminder'),
);
}
}
@ -48,16 +50,17 @@ class MyHomePage extends StatefulWidget {
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
final ScrollTable _checkboxes = ScrollTable(title: "TODOs");
int _counter = 1;
void _incrementCounter() {
void _addDummyTask() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// stuff without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
_checkboxes.addTask(RepeatingTask(title: "Dummy Task #$_counter", begin: DateTime.now(), repeat: _counter++));
});
}
@ -78,36 +81,11 @@ class _MyHomePageState extends State<MyHomePage> {
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
child: _checkboxes,
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
onPressed: _addDummyTask,
tooltip: 'add dummy Task',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);

35
lib/repeating_task.dart Normal file
View File

@ -0,0 +1,35 @@
import 'package:flutter/material.dart';
import 'package:nextcloud_reminder/task_item.dart';
class RepeatingTask extends StatefulWidget {
const RepeatingTask({super.key, required this.title, required this.begin, this.repeat=1});
final String title;
final DateTime begin;
final int repeat;
@override
State<StatefulWidget> createState() => _RepeatingTaskState();
}
class _RepeatingTaskState extends State<RepeatingTask> {
late List<TaskItem> _occurrences;
late DateTime _first_occurence;
late String _title;
@override
void initState() {
super.initState();
_title = widget.title;
_first_occurence = widget.begin;
_occurrences = List<TaskItem>.generate(10, (index) => TaskItem(done: index % widget.repeat == 0 ? false : null));
}
@override
Widget build(BuildContext context) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: _occurrences,
);
}
}

72
lib/table.dart Normal file
View File

@ -0,0 +1,72 @@
import 'package:flutter/material.dart';
import 'package:nextcloud_reminder/repeating_task.dart';
class ScrollTable extends StatefulWidget {
ScrollTable({super.key, required this.title});
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
final _ScrollTableState _internalState = _ScrollTableState();
@override
State<ScrollTable> createState() => _internalState;
void addTask(RepeatingTask task) {
_internalState.addTask(task);
}
}
class _ScrollTableState extends State<ScrollTable> {
final List<RepeatingTask> _content = [];
addTask(RepeatingTask task) {
setState(() {
_content.add(task);
});
}
List<Widget> _buildTitles() {
return List<Widget>.from(_content.map((RepeatingTask t) =>
Container(
alignment: Alignment.center,
width: 120.0,
height: 60.0,
color: Colors.white,
margin: const EdgeInsets.all(4.0),
child: Text(t.title, style: Theme
.of(context)
.textTheme
.labelMedium),
)));
}
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: _buildTitles(),
),
Flexible(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: _content,
),
),
)
],
)
);
}
}

36
lib/task_item.dart Normal file
View File

@ -0,0 +1,36 @@
import 'package:flutter/material.dart';
class TaskItem extends StatefulWidget {
final bool? done;
const TaskItem({super.key, this.done});
@override
State<TaskItem> createState() => _TaskItemState();
}
class _TaskItemState extends State<TaskItem>{
bool? _done;
@override
void initState() {
super.initState();
_done = widget.done;
}
@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.center,
width: 60.0,
height: 60.0,
color: Colors.white,
margin: const EdgeInsets.all(4.0),
child: _done == null ? null : Checkbox(value: _done, onChanged: (newState) => setState(() {
_done = newState!;
})),
);
}
}