fix: Add labels to each cubit using repositories and state properties, remove label cubits

This commit is contained in:
Anton Stubenbord
2023-04-04 20:30:25 +02:00
parent 78fbd042a6
commit a2388b014b
95 changed files with 4790 additions and 1823 deletions

View File

@@ -1,37 +1,24 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/core/repository/label_repository.dart';
import 'package:paperless_mobile/features/labels/cubit/label_cubit.dart';
class LabelText<T extends Label> extends StatelessWidget {
final int? id;
final T? label;
final String placeholder;
final TextStyle? style;
const LabelText({
super.key,
this.style,
this.id,
this.placeholder = "",
required this.label,
});
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => LabelCubit<T>(
context.read<LabelRepository<T>>(),
),
child: BlocBuilder<LabelCubit<T>, LabelState<T>>(
builder: (context, state) {
return Text(
state.labels[id]?.toString() ?? placeholder,
style: style,
maxLines: 1,
overflow: TextOverflow.ellipsis,
);
},
),
return Text(
label?.toString() ?? placeholder,
style: style,
maxLines: 1,
overflow: TextOverflow.ellipsis,
);
;
}