dartboard_resume/lib/annotation_manager.dart
2024-09-10 15:09:15 -06:00

45 lines
1.1 KiB
Dart

import 'package:dartboard_resume/widgets/footnote.dart';
import 'package:pdf/widgets.dart';
class AnnotationManager {
// Factory constructor to return the single instance
factory AnnotationManager() {
return _instance;
}
// Private constructor
AnnotationManager._privateConstructor();
// Static field to hold the single instance of the class
static final AnnotationManager _instance = AnnotationManager._privateConstructor();
// Field to hold the number
int _numUrls = 0;
List<Widget> _urlWidgets = [];
TextStyle? _style;
// ignore: avoid_setters_without_getters
set style(TextStyle style) => _style = style;
int add({required String url}) {
_numUrls += 1;
if (_style == null) {
throw Exception('Must provide text style for urls');
}
_urlWidgets.add(Footnote(number: _numUrls, style: _style!, url: url));
return _numUrls;
}
List<Widget> get footnotes {
final widgets = [..._urlWidgets];
reset();
return widgets;
}
// Method to reset the number
void reset() {
_numUrls = 0;
_urlWidgets = [];
}
}