Files
GitJournal/lib/repository_manager.dart
2021-02-12 15:39:08 +01:00

79 lines
1.7 KiB
Dart

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:path/path.dart' as p;
import 'package:shared_preferences/shared_preferences.dart';
import 'package:gitjournal/repository.dart';
import 'package:gitjournal/settings.dart';
class RepositoryInfo {
String id;
String folderName;
IconData iconData;
RepositoryInfo.fromMap(Map<String, dynamic> map) {
id = map['id'];
folderName = map['folderName'];
iconData = IconData(map['iconData'] as int);
}
Map<String, dynamic> toMap() => {
'id': id,
'folderName': folderName,
'iconData': iconData.codePoint,
};
}
// Make this info a change notifier where the current value is ?
// -> things required to create the Repo?
class RepositoryManager with ChangeNotifier {
List<String> repoIds;
String currentId;
Repository _repo;
final String gitBaseDir;
final String cacheDir;
final SharedPreferences pref;
RepositoryManager({
@required this.gitBaseDir,
@required this.cacheDir,
@required this.pref,
}) {
// From the pref load all the RepositoryInfos
}
Repository get currentRepo => _repo;
Future<Repository> buildActiveRepository() async {
if (_repo != null) {
return _repo;
}
currentId ??= DEFAULT_ID;
var repoCacheDir = p.join(cacheDir, currentId);
await Directory(repoCacheDir).create(recursive: true);
_repo = await Repository.load(
gitBaseDir: gitBaseDir,
cacheDir: repoCacheDir,
pref: pref,
id: currentId,
);
notifyListeners();
return _repo;
}
// call notifyObservers();
// --> After that what?
// addRepo(info) -> id
// removeRepo(id)
// selectRepo(id)
// updateRepo(id, info)
}