Compare commits

..

34 Commits

Author SHA1 Message Date
kolaente 873bcef161
format 2020-06-25 10:10:00 +02:00
kolaente 11e5711aab
Move all maxPages related stuff to provider 2020-06-25 10:07:37 +02:00
kolaente d4dbc5b4ae
Use provider to add a new task 2020-06-24 11:12:14 +02:00
kolaente a89068bbdf
Merge branch 'master' into feature/task-list
# Conflicts:
#	pubspec.lock
#	pubspec.yaml
2020-06-24 10:57:14 +02:00
kolaente ac2d9722e9
Make _loadList async to make it satisfy the refresh listener 2020-06-16 16:15:20 +02:00
kolaente 7bd340f45c
Start using providers 2020-06-16 16:04:18 +02:00
kolaente bc8188f44c
Format 2020-06-16 00:34:25 +02:00
kolaente 972b194f56
Enable multiple order parameters 2020-06-16 00:33:09 +02:00
kolaente 9f37496497
Merge branch 'master' into feature/task-list 2020-06-16 00:18:37 +02:00
kolaente db9be17857
Merge branch 'master' into feature/task-list
# Conflicts:
#	lib/models/task.dart
2020-06-15 23:48:50 +02:00
kolaente 38c7348aa8
Format 2020-06-15 23:48:01 +02:00
kolaente 876ac88a1d
Merge branch 'master' into feature/task-list
# Conflicts:
#	lib/models/task.dart
2020-06-15 23:47:26 +02:00
kolaente 9348e6acc5
Cleanup 2020-04-27 19:39:21 +02:00
kolaente bb6139cef7
Fix loading state not being set 2020-04-27 19:38:04 +02:00
kolaente 9fd47cde57
Add workaround for pagination 2020-04-27 18:39:28 +02:00
kolaente a34daacf23
Fix next page condition not working 2020-04-27 18:27:26 +02:00
kolaente 25d64f14a5
Merge with master 2020-04-27 17:24:00 +02:00
kolaente 413c2703e6
Fix crash when no due date was present 2020-04-27 17:18:50 +02:00
kolaente e110a4b9eb
Format 2020-04-27 17:09:10 +02:00
kolaente c146add9bf
Merge with master 2020-04-27 17:08:20 +02:00
kolaente d08c7c3e70
format 2020-01-16 22:10:51 +01:00
kolaente 5f7d59c7ea
Don't try to show a task tile if there is none for the current index 2020-01-16 22:08:26 +01:00
kolaente 78ddbecd19
Merge branch 'master' into feature/task-list 2020-01-15 23:38:17 +01:00
kolaente 6fc336223b
Format 2020-01-15 23:33:33 +01:00
kolaente b5363cb6ac
Add fixme 2020-01-15 23:32:43 +01:00
kolaente 96dbddb10c
Fix scrolling to last element 2020-01-15 23:29:31 +01:00
kolaente 53dfe7327b
Add basic infinite scrolling (still has bugs) 2020-01-15 22:59:07 +01:00
kolaente ea8ba3cfd9
Format 2020-01-13 23:16:26 +01:00
kolaente ac67ccbd4c
Note 2020-01-13 23:15:50 +01:00
kolaente b36f0215d8
Add sorting for tasks 2020-01-13 23:14:51 +01:00
kolaente 2345a131b7
Add optional query params to api get function 2020-01-13 23:09:32 +01:00
kolaente 187337c580
Format 2020-01-13 22:47:40 +01:00
kolaente cf9c9b4cb4
Fix crash after save 2020-01-13 22:47:10 +01:00
kolaente 9833ef4885
Re-implemented getting tasks with the new seperate endpoint 2020-01-13 22:31:15 +01:00
28 changed files with 414 additions and 193 deletions

View File

@ -23,6 +23,7 @@ steps:
image: cirrusci/flutter:stable
pull: true
commands:
- sudo chown cirrus . -R # The clone step clones everything as root, this is our "fix" until we find a better solution
- flutter packages get
- make format-check
- make build-debug
@ -61,6 +62,7 @@ steps:
image: cirrusci/flutter:stable
pull: true
commands:
- sudo chown cirrus . -R # The clone step clones everything as root, this is our "fix" until we find a better solution
- flutter packages get
- make build-all
- mkdir apks
@ -71,13 +73,12 @@ steps:
image: plugins/s3:1
pull: true
settings:
bucket: vikunja-releases
bucket: vikunja
access_key:
from_secret: aws_access_key_id
secret_key:
from_secret: aws_secret_access_key
endpoint: https://s3.fr-par.scw.cloud
region: fr-par
endpoint: https://storage.kolaente.de
path_style: true
strip_prefix: apks/
source: apks/*
@ -107,6 +108,7 @@ steps:
image: cirrusci/flutter:stable
pull: true
commands:
- sudo chown cirrus . -R # The clone step clones everything as root, this is our "fix" until we find a better solution
- flutter packages get
- make build-all
- mkdir apks
@ -116,13 +118,12 @@ steps:
image: plugins/s3:1
pull: true
settings:
bucket: vikunja-releases
bucket: vikunja
access_key:
from_secret: aws_access_key_id
secret_key:
from_secret: aws_secret_access_key
endpoint: https://s3.fr-par.scw.cloud
region: fr-par
endpoint: https://storage.kolaente.de
path_style: true
strip_prefix: apks/
source: apks/*
@ -177,13 +178,9 @@ steps:
CONTACT_PHONE:
from_secret: contact_phone
commands:
- eval "$(rbenv init -)"
- rbenv shell 2.5.0
- cd ios
- bundle config set --local path '.vendor/bundle'
- bundle install
- bundle exec fastlane ios signing
- bundle exec fastlane ios beta
- fastlane ios signing
- fastlane ios beta
depends_on:
- testing
- testing

View File

@ -1,8 +1,7 @@
# Vikunja Cross-Platform app
# Vikunja Cross-Plattform app
[![Build Status](https://drone.kolaente.de/api/badges/vikunja/app/status.svg)](https://drone.kolaente.de/vikunja/app)
[![Build Status](https://drone1.kolaente.de/api/badges/vikunja/app/status.svg)](https://drone1.kolaente.de/vikunja/app)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![Download](https://img.shields.io/badge/download-v0.1-brightgreen.svg)](https://storage.kolaente.de/minio/vikunja-app/)
[![TestFlight Beta](https://img.shields.io/badge/TestFlight-Beta-026CBB)](https://testflight.apple.com/join/KxOaAraq)
Vikunja as Flutter cross-platform app.
Vikunja as Flutter cross platform app.

View File

@ -13,6 +13,7 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="Vikunja"
android:icon="@mipmap/ic_launcher">
<activity
@ -22,13 +23,17 @@
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</activity>
</application>
</manifest>

View File

@ -1,5 +1,13 @@
package io.vikunja.flutteringvikunja
import io.flutter.embedding.android.FlutterActivity
import android.os.Bundle
class MainActivity : FlutterActivity()
import io.flutter.app.FlutterActivity
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity(): FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
GeneratedPluginRegistrant.registerWith(this)
}
}

View File

@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-bin.zip

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -0,0 +1,11 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/opt/flutter"
export "FLUTTER_APPLICATION_PATH=/home/jonasfranz/Projects/vikunja/app"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "OTHER_LDFLAGS=$(inherited) -framework Flutter"
export "FLUTTER_FRAMEWORK_DIR=/opt/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_BUILD_NAME=0.1.0"
export "FLUTTER_BUILD_NUMBER=0.1.0"

View File

@ -10,32 +10,78 @@ project 'Runner', {
'Release' => :release,
}
def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
def parse_KV_file(file, separator='=')
file_abs_path = File.expand_path(file)
if !File.exists? file_abs_path
return [];
end
File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
generated_key_values = {}
skip_line_start_symbols = ["#", "/"]
File.foreach(file_abs_path) do |line|
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
plugin = line.split(pattern=separator)
if plugin.length == 2
podname = plugin[0].strip()
path = plugin[1].strip()
podpath = File.expand_path("#{path}", file_abs_path)
generated_key_values[podname] = podpath
else
puts "Invalid plugin specification: #{line}"
end
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
generated_key_values
end
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
flutter_ios_podfile_setup
target 'Runner' do
use_frameworks!
use_modular_headers!
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
# Flutter Pod
copied_flutter_dir = File.join(__dir__, 'Flutter')
copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec')
unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path)
# Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet.
# That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration.
# CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist.
generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig')
unless File.exist?(generated_xcode_build_settings_path)
raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end
generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path)
cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR'];
unless File.exist?(copied_framework_path)
FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
end
unless File.exist?(copied_podspec_path)
FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir)
end
end
# Keep pod path relative so it can be checked into Podfile.lock.
pod 'Flutter', :path => 'Flutter'
# Plugin Pods
# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
# referring to absolute paths on developers' machines.
system('rm -rf .symlinks')
system('mkdir -p .symlinks/plugins')
plugin_pods = parse_KV_file('../.flutter-plugins')
plugin_pods.each do |name, path|
symlink = File.join('.symlinks', 'plugins', name)
File.symlink(path, symlink)
pod name, :path => File.join(symlink, 'ios')
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end

View File

@ -312,6 +312,7 @@
/* Begin XCBuildConfiguration section */
97C147031CF9000F007C117D /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
@ -365,6 +366,7 @@
};
97C147041CF9000F007C117D /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;

View File

@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:vikunja_app/api/response.dart';
class Client {
final JsonDecoder _decoder = new JsonDecoder();
@ -25,33 +26,45 @@ class Client {
'Content-Type': 'application/json'
};
Future<dynamic> get(String url) {
return http
.get('${this.base}$url', headers: _headers)
.then(_handleResponse);
Future<Response> get(String url,
[Map<String, List<String>> queryParameters]) {
// TODO: This could be moved to a seperate function
var uri = Uri.parse('${this.base}$url');
// Because these are all final values, we can't just add the queryParameters and must instead build a new Uri Object every time this method is called.
var newUri = Uri(
scheme: uri.scheme,
userInfo: uri.userInfo,
host: uri.host,
port: uri.port,
path: uri.path,
query: uri.query,
queryParameters: queryParameters,
// Because dart takes a Map<String, String> here, it is only possible to sort by one parameter while the api supports n parameters.
fragment: uri.fragment);
return http.get(newUri, headers: _headers).then(_handleResponse);
}
Future<dynamic> delete(String url) {
Future<Response> delete(String url) {
return http
.delete('${this.base}$url', headers: _headers)
.then(_handleResponse);
}
Future<dynamic> post(String url, {dynamic body}) {
Future<Response> post(String url, {dynamic body}) {
return http
.post('${this.base}$url',
headers: _headers, body: _encoder.convert(body))
.then(_handleResponse);
}
Future<dynamic> put(String url, {dynamic body}) {
Future<Response> put(String url, {dynamic body}) {
return http
.put('${this.base}$url',
headers: _headers, body: _encoder.convert(body))
.then(_handleResponse);
}
dynamic _handleResponse(http.Response response) {
Response _handleResponse(http.Response response) {
if (response.statusCode < 200 ||
response.statusCode >= 400 ||
json == null) {
@ -65,12 +78,14 @@ class Client {
throw new ApiException(
response.statusCode, response.request.url.toString());
}
return _decoder.convert(response.body);
return new Response(
_decoder.convert(response.body), response.statusCode, response.headers);
}
}
class InvalidRequestApiException extends ApiException {
final String message;
InvalidRequestApiException(int errorCode, String path, this.message)
: super(errorCode, path);
@ -83,6 +98,7 @@ class InvalidRequestApiException extends ApiException {
class ApiException implements Exception {
final int errorCode;
final String path;
ApiException(this.errorCode, this.path);
@override

View File

@ -12,7 +12,7 @@ class ListAPIService extends APIService implements ListService {
Future<TaskList> create(namespaceId, TaskList tl) {
return client
.put('/namespaces/$namespaceId/lists', body: tl.toJSON())
.then((map) => TaskList.fromJson(map));
.then((response) => TaskList.fromJson(response.body));
}
@override
@ -22,25 +22,27 @@ class ListAPIService extends APIService implements ListService {
@override
Future<TaskList> get(int listId) {
return client.get('/lists/$listId').then((map) => TaskList.fromJson(map));
return client
.get('/lists/$listId')
.then((response) => TaskList.fromJson(response.body));
}
@override
Future<List<TaskList>> getAll() {
return client.get('/lists').then(
(list) => convertList(list, (result) => TaskList.fromJson(result)));
return client.get('/lists').then((response) =>
convertList(response.body, (result) => TaskList.fromJson(result)));
}
@override
Future<List<TaskList>> getByNamespace(int namespaceId) {
return client.get('/namespaces/$namespaceId/lists').then(
(list) => convertList(list, (result) => TaskList.fromJson(result)));
return client.get('/namespaces/$namespaceId/lists').then((response) =>
convertList(response.body, (result) => TaskList.fromJson(result)));
}
@override
Future<TaskList> update(TaskList tl) {
return client
.post('/lists/${tl.id}', body: tl.toJSON())
.then((map) => TaskList.fromJson(map));
.then((response) => TaskList.fromJson(response.body));
}
}

View File

@ -12,7 +12,7 @@ class NamespaceAPIService extends APIService implements NamespaceService {
Future<Namespace> create(Namespace ns) {
return client
.put('/namespaces', body: ns.toJSON())
.then((map) => Namespace.fromJson(map));
.then((response) => Namespace.fromJson(response.body));
}
@override
@ -24,19 +24,19 @@ class NamespaceAPIService extends APIService implements NamespaceService {
Future<Namespace> get(int namespaceId) {
return client
.get('/namespaces/$namespaceId')
.then((map) => Namespace.fromJson(map));
.then((response) => Namespace.fromJson(response.body));
}
@override
Future<List<Namespace>> getAll() {
return client.get('/namespaces').then(
(list) => convertList(list, (result) => Namespace.fromJson(result)));
return client.get('/namespaces').then((response) =>
convertList(response.body, (result) => Namespace.fromJson(result)));
}
@override
Future<Namespace> update(Namespace ns) {
return client
.post('/namespaces/${ns.id}', body: ns.toJSON())
.then((map) => Namespace.fromJson(map));
.then((response) => Namespace.fromJson(response.body));
}
}

9
lib/api/response.dart Normal file
View File

@ -0,0 +1,9 @@
// This is a wrapper class to be able to return the headers up to the provider
// to properly handle things like pagination with it.
class Response {
Response(this.body, this.statusCode, this.headers);
final dynamic body;
final int statusCode;
final Map<String, String> headers;
}

View File

@ -1,6 +1,7 @@
import 'dart:async';
import 'package:vikunja_app/api/client.dart';
import 'package:vikunja_app/api/response.dart';
import 'package:vikunja_app/api/service.dart';
import 'package:vikunja_app/models/task.dart';
import 'package:vikunja_app/service/services.dart';
@ -12,7 +13,7 @@ class TaskAPIService extends APIService implements TaskService {
Future<Task> add(int listId, Task task) {
return client
.put('/lists/$listId', body: task.toJSON())
.then((map) => Task.fromJson(map));
.then((response) => Task.fromJson(response.body));
}
@override
@ -24,6 +25,16 @@ class TaskAPIService extends APIService implements TaskService {
Future<Task> update(Task task) {
return client
.post('/tasks/${task.id}', body: task.toJSON())
.then((map) => Task.fromJson(map));
.then((response) => Task.fromJson(response.body));
}
@override
Future<Response> getAll(int listId,
[Map<String, List<String>> queryParameters]) {
return client.get('/lists/$listId/tasks', queryParameters).then(
(response) => new Response(
convertList(response.body, (result) => Task.fromJson(result)),
response.statusCode,
response.headers));
}
}

View File

@ -13,7 +13,7 @@ class UserAPIService extends APIService implements UserService {
var token = await client.post('/login', body: {
'username': username,
'password': password
}).then((map) => map['token']);
}).then((response) => response.body['token']);
return UserAPIService(Client(token, client.base))
.getCurrentUser()
.then((user) => UserTokenPair(user, token));
@ -25,12 +25,12 @@ class UserAPIService extends APIService implements UserService {
'username': username,
'email': email,
'password': password
}).then((resp) => resp['username']);
}).then((response) => response.body['username']);
return login(newUser, password);
}
@override
Future<User> getCurrentUser() {
return client.get('/user').then((map) => User.fromJson(map));
return client.get('/user').then((response) => User.fromJson(response.body));
}
}

2
lib/constants.dart Normal file
View File

@ -0,0 +1,2 @@
const SENTRY_DSN =
'https://b070ed4bd1d043428db6fe7d1ce57908@sentry.kolaente.de/5';

View File

@ -1,10 +1,54 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:sentry/sentry.dart';
import 'package:vikunja_app/constants.dart';
import 'package:vikunja_app/global.dart';
import 'package:vikunja_app/pages/home.dart';
import 'package:vikunja_app/pages/user/login.dart';
import 'package:vikunja_app/theme/theme.dart';
void main() => runApp(VikunjaGlobal(
void main() {
if (!kReleaseMode) {
// only log errors in release mode
_startApp();
return;
}
var sentry = new SentryClient(dsn: SENTRY_DSN);
FlutterError.onError = (details, {bool forceReport = false}) {
try {
sentry.captureException(
exception: details.exception,
stackTrace: details.stack,
);
} catch (e) {
print('Sending report to sentry.io failed: $e');
} finally {
// Also use Flutter's pretty error logging to the device's console.
FlutterError.dumpErrorToConsole(details, forceReport: forceReport);
}
};
runZoned(
_startApp,
onError: (Object error, StackTrace stackTrace) {
try {
sentry.captureException(
exception: error,
stackTrace: stackTrace,
);
print('Error sent to sentry.io: $error');
} catch (e) {
print('Sending report to sentry.io failed: $e');
print('Original error: $error');
}
},
);
}
_startApp() => runApp(VikunjaGlobal(
child: new VikunjaApp(home: HomePage()),
login: new VikunjaApp(home: LoginPage())));

View File

@ -1,5 +1,4 @@
import 'package:meta/meta.dart';
import 'package:vikunja_app/models/task.dart';
import 'package:vikunja_app/models/user.dart';
class TaskList {
@ -7,7 +6,6 @@ class TaskList {
final String title, description;
final User owner;
final DateTime created, updated;
final List<Task> tasks;
TaskList(
{@required this.id,
@ -15,8 +13,7 @@ class TaskList {
this.description,
this.owner,
this.created,
this.updated,
this.tasks});
this.updated});
TaskList.fromJson(Map<String, dynamic> json)
: id = json['id'],
@ -24,10 +21,7 @@ class TaskList {
description = json['description'],
title = json['title'],
updated = DateTime.parse(json['updated']),
created = DateTime.parse(json['created']),
tasks = (json['tasks'] == null ? [] : json['tasks'] as List<dynamic>)
?.map((taskJson) => Task.fromJson(taskJson))
?.toList();
created = DateTime.parse(json['created']);
toJSON() {
return {

View File

@ -27,12 +27,16 @@ class Task {
reminders = (json['reminder_dates'] as List<dynamic>)
?.map((r) => DateTime.parse(r))
?.toList(),
due =
json['due_date'] != null ? DateTime.parse(json['due_date']) : null,
due = json['due_date'].toString() == 'null'
? null
: DateTime.parse(json['due_date']),
description = json['description'],
title = json['title'],
done = json['done'],
owner = User.fromJson(json['created_by']);
owner = json['created_by'].toString() == "null"
? null
: User.fromJson(json[
'created_by']); // There has to be a better way of doing this...
toJSON() => {
'id': id,

View File

@ -1,12 +1,12 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:vikunja_app/components/AddDialog.dart';
import 'package:vikunja_app/components/TaskTile.dart';
import 'package:vikunja_app/global.dart';
import 'package:vikunja_app/models/list.dart';
import 'package:vikunja_app/models/task.dart';
import 'package:vikunja_app/pages/list/list_edit.dart';
import 'package:vikunja_app/stores/list_store.dart';
class ListPage extends StatefulWidget {
final TaskList taskList;
@ -19,24 +19,18 @@ class ListPage extends StatefulWidget {
class _ListPageState extends State<ListPage> {
TaskList _list;
List<Task> _loadingTasks = [];
bool _loading = true;
int _currentPage = 1;
@override
void initState() {
_list = TaskList(
id: widget.taskList.id, title: widget.taskList.title, tasks: []);
_list = TaskList(id: widget.taskList.id, title: widget.taskList.title);
Future.microtask(() => _loadList());
super.initState();
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
_loadList();
}
@override
Widget build(BuildContext context) {
final taskState = Provider.of<ListProvider>(context);
return Scaffold(
appBar: AppBar(
title: new Text(_list.title),
@ -51,15 +45,31 @@ class _ListPageState extends State<ListPage> {
))))
],
),
body: !this._loading
body: !taskState.isLoading
? RefreshIndicator(
child: _list.tasks.length > 0
? ListView(
child: taskState.tasks.length > 0
? ListView.builder(
padding: EdgeInsets.symmetric(vertical: 8.0),
children: ListTile.divideTiles(
context: context, tiles: _listTasks())
.toList(),
)
itemBuilder: (context, i) {
if (i.isOdd) return Divider();
final index = i ~/ 2;
// This handles the case if there are no more elements in the list left which can be provided by the api
if (taskState.maxPages == _currentPage &&
index == taskState.tasks.length - 1) return null;
if (index >= taskState.tasks.length &&
_currentPage < taskState.maxPages) {
_currentPage++;
_loadTasksForPage(_currentPage);
}
return index < taskState.tasks.length
? TaskTile(
task: taskState.tasks[index],
)
: null;
})
: Center(child: Text('This list is empty.')),
onRefresh: _loadList,
)
@ -70,56 +80,31 @@ class _ListPageState extends State<ListPage> {
));
}
List<Widget> _listTasks() {
var tasks = (_list?.tasks?.map(_buildTile) ?? []).toList();
tasks.addAll(_loadingTasks.map(_buildLoadingTile));
return tasks;
Future<void> _loadList() async {
_loadTasksForPage(1);
}
TaskTile _buildTile(Task task) {
return TaskTile(task: task, loading: false);
}
TaskTile _buildLoadingTile(Task task) {
return TaskTile(
task: task,
loading: true,
void _loadTasksForPage(int page) {
Provider.of<ListProvider>(context, listen: false).loadTasks(
context: context,
listId: _list.id,
page: page,
);
}
Future<void> _loadList() {
return VikunjaGlobal.of(context)
.listService
.get(widget.taskList.id)
.then((list) {
setState(() {
_loading = false;
_list = list;
});
});
}
_addItemDialog(BuildContext context) {
showDialog(
context: context,
builder: (_) => AddDialog(
onAdd: (name) => _addItem(name, context),
onAdd: (title) => _addItem(title, context),
decoration: new InputDecoration(
labelText: 'Task Name', hintText: 'eg. Milk')));
}
_addItem(String name, BuildContext context) {
var globalState = VikunjaGlobal.of(context);
var newTask = Task(
id: null, title: name, owner: globalState.currentUser, done: false);
setState(() => _loadingTasks.add(newTask));
globalState.taskService.add(_list.id, newTask).then((task) {
setState(() {
_list.tasks.add(task);
});
}).then((_) {
_loadList();
setState(() => _loadingTasks.remove(newTask));
_addItem(String title, BuildContext context) {
Provider.of<ListProvider>(context, listen: false)
.addTask(context: context, title: title, listId: _list.id)
.then((_) {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text('The task was added successfully!'),
));

View File

@ -3,12 +3,14 @@ import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:after_layout/after_layout.dart';
import 'package:provider/provider.dart';
import 'package:vikunja_app/components/AddDialog.dart';
import 'package:vikunja_app/global.dart';
import 'package:vikunja_app/models/list.dart';
import 'package:vikunja_app/models/namespace.dart';
import 'package:vikunja_app/pages/list/list.dart';
import 'package:vikunja_app/stores/list_store.dart';
class NamespacePage extends StatefulWidget {
final Namespace namespace;
@ -89,6 +91,7 @@ class _NamespacePageState extends State<NamespacePage>
}
Future<void> _loadLists() {
// FIXME: This is called even when the tasks on a list are loaded - which is not needed at all
return VikunjaGlobal.of(context)
.listService
.getByNamespace(widget.namespace.id)
@ -99,8 +102,14 @@ class _NamespacePageState extends State<NamespacePage>
}
_openList(BuildContext context, TaskList list) {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => ListPage(taskList: list)));
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => ChangeNotifierProvider<ListProvider>(
create: (_) => new ListProvider(),
child: ListPage(
taskList: list,
),
),
));
}
_addListDialog(BuildContext context) {
@ -116,7 +125,7 @@ class _NamespacePageState extends State<NamespacePage>
_addList(String name, BuildContext context) {
VikunjaGlobal.of(context)
.listService
.create(widget.namespace.id, TaskList(id: null, title: name, tasks: []))
.create(widget.namespace.id, TaskList(id: null, title: name))
.then((_) {
setState(() {});
_loadLists();

View File

@ -1,5 +1,6 @@
import 'dart:async';
import 'package:vikunja_app/api/response.dart';
import 'package:vikunja_app/models/list.dart';
import 'package:vikunja_app/models/namespace.dart';
import 'package:vikunja_app/models/task.dart';
@ -28,7 +29,6 @@ var _lists = {
1: TaskList(
id: 1,
title: 'List 1',
tasks: _tasks.values.toList(),
owner: _users[1],
description: 'A nice list',
created: DateTime.now(),
@ -120,20 +120,13 @@ class MockedListService implements ListService {
class MockedTaskService implements TaskService {
@override
Future delete(int taskId) {
_lists.forEach(
(_, list) => list.tasks.removeWhere((task) => task.id == taskId));
_tasks.remove(taskId);
return Future.value();
}
@override
Future<Task> update(Task task) {
_lists.forEach((_, list) {
if (list.tasks.where((t) => t.id == task.id).length > 0) {
list.tasks.removeWhere((t) => t.id == task.id);
list.tasks.add(task);
}
});
_tasks[task.id] = task;
return Future.value(_tasks[task.id] = task);
}
@ -141,9 +134,17 @@ class MockedTaskService implements TaskService {
Future<Task> add(int listId, Task task) {
var id = _tasks.keys.last + 1;
_tasks[id] = task;
_lists[listId].tasks.add(task);
return Future.value(task);
}
@override
Future<Response> getAll(int listId,
[Map<String, List<String>> queryParameters]) {
return Future.value(new Response(_tasks.values.toList(), 200, {}));
}
@override
int get maxPages => 1;
}
class MockedUserService implements UserService {

View File

@ -1,5 +1,6 @@
import 'dart:async';
import 'package:vikunja_app/api/response.dart';
import 'package:vikunja_app/models/list.dart';
import 'package:vikunja_app/models/namespace.dart';
import 'package:vikunja_app/models/task.dart';
@ -26,6 +27,8 @@ abstract class TaskService {
Future<Task> update(Task task);
Future delete(int taskId);
Future<Task> add(int listId, Task task);
Future<Response> getAll(int listId,
[Map<String, List<String>> queryParameters]);
}
abstract class UserService {

View File

@ -0,0 +1,54 @@
import 'package:flutter/material.dart';
import 'package:vikunja_app/models/task.dart';
import 'package:vikunja_app/global.dart';
class ListProvider with ChangeNotifier {
bool _isLoading = false;
int _maxPages = 0;
// TODO: Streams
List<Task> _tasks = [];
bool get isLoading => _isLoading;
int get maxPages => _maxPages;
set tasks(List<Task> tasks) {
_tasks = tasks;
notifyListeners();
}
List<Task> get tasks => _tasks;
void loadTasks({BuildContext context, int listId, int page = 1}) {
_isLoading = true;
notifyListeners();
VikunjaGlobal.of(context).taskService.getAll(listId, {
"sort_by": ["done", "id"],
"order_by": ["asc", "desc"],
"page": [page.toString()]
}).then((response) {
if (response.headers["x-pagination-total-pages"] != null) {
_maxPages = int.parse(response.headers["x-pagination-total-pages"]);
}
_tasks.addAll(response.body);
_isLoading = false;
notifyListeners();
});
}
Future<void> addTask({BuildContext context, String title, int listId}) {
var globalState = VikunjaGlobal.of(context);
var newTask = Task(
id: null, title: title, owner: globalState.currentUser, done: false);
_isLoading = true;
notifyListeners();
return globalState.taskService.add(listId, newTask).then((task) {
_tasks.insert(0, task);
_isLoading = false;
notifyListeners();
});
}
}

View File

@ -28,42 +28,28 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0-nullsafety.1"
version: "2.4.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.1"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.3"
version: "2.0.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.1"
version: "1.1.3"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0-nullsafety.3"
version: "1.14.12"
convert:
dependency: transitive
description:
@ -85,13 +71,15 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
fake_async:
dart_config:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.1"
path: "."
ref: HEAD
resolved-ref: a7ed88a4793e094a4d5d5c2d88a89e55510accde
url: "https://github.com/MarkOSullivan94/dart_config.git"
source: git
version: "0.5.0"
flutter:
dependency: "direct main"
description: flutter
@ -103,14 +91,14 @@ packages:
name: flutter_launcher_icons
url: "https://pub.dartlang.org"
source: hosted
version: "0.8.1"
version: "0.6.1"
flutter_secure_storage:
dependency: "direct main"
description:
name: flutter_secure_storage
url: "https://pub.dartlang.org"
source: hosted
version: "3.3.5"
version: "3.3.3"
flutter_test:
dependency: "direct dev"
description: flutter
@ -122,7 +110,7 @@ packages:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.0+3"
version: "0.12.1"
http_parser:
dependency: transitive
description:
@ -143,21 +131,28 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10-nullsafety.1"
version: "0.12.6"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.3"
version: "1.1.8"
nested:
dependency: transitive
description:
name: nested
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.4"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0-nullsafety.1"
version: "1.6.4"
pedantic:
dependency: transitive
description:
@ -172,6 +167,27 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
provider:
dependency: "direct main"
description:
name: provider
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.5+1"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
sentry:
dependency: "direct main"
description:
name: sentry
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
sky_engine:
dependency: transitive
description: flutter
@ -183,56 +199,63 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0-nullsafety.2"
version: "1.7.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0-nullsafety.1"
version: "1.9.3"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.1"
version: "2.0.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.1"
version: "1.0.5"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.1"
version: "1.1.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19-nullsafety.2"
version: "0.2.15"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.3"
version: "1.1.6"
usage:
dependency: transitive
description:
name: usage
url: "https://pub.dartlang.org"
source: hosted
version: "3.4.1"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.3"
version: "2.0.8"
xml:
dependency: transitive
description:
@ -248,5 +271,5 @@ packages:
source: hosted
version: "2.2.0"
sdks:
dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.20.0 <2.0.0"
dart: ">=2.6.0 <3.0.0"
flutter: ">=1.12.1"

View File

@ -10,14 +10,16 @@ dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.3
flutter_secure_storage: 3.3.5
http: 0.12.0+3
flutter_secure_storage: ^3.3.3
http: ^0.12.1
after_layout: ^1.0.7
sentry: ^3.0.1
provider: ^4.0.5
dev_dependencies:
flutter_test:
sdk: flutter
flutter_launcher_icons: "^0.8.0"
flutter_launcher_icons: "^0.6.1"
flutter_icons:
image_path: "assets/vikunja_logo.png"

View File

@ -1,6 +0,0 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base"
]
}