forked from kherel/selfprivacy.org.app
parent
21611e63c7
commit
f53ad044c1
@ -1,32 +1,53 @@ |
||||
import 'package:flutter_bloc/flutter_bloc.dart'; |
||||
import 'package:selfprivacy/config/get_it_config.dart'; |
||||
import 'package:selfprivacy/logic/api_maps/server.dart'; |
||||
import 'package:selfprivacy/logic/cubit/users/users_cubit.dart'; |
||||
import 'package:selfprivacy/logic/models/jobs/job.dart'; |
||||
import 'package:equatable/equatable.dart'; |
||||
import 'package:selfprivacy/logic/models/user.dart'; |
||||
export 'package:provider/provider.dart'; |
||||
|
||||
part 'jobs_state.dart'; |
||||
|
||||
class JobsCubit extends Cubit<JobsState> { |
||||
JobsCubit() : super(JobsState.emtpy()); |
||||
JobsCubit(this.usersCubit) : super(JobsStateEmpty()); |
||||
|
||||
final api = ServerApi(); |
||||
final UsersCubit usersCubit; |
||||
|
||||
void addJob(Job job) { |
||||
final newState = state.addJob(job); |
||||
emit(newState); |
||||
var newJobsList = <Job>[]; |
||||
if (state is JobsStateWithJobs) { |
||||
newJobsList.addAll((state as JobsStateWithJobs).jobList); |
||||
} |
||||
newJobsList.add(job); |
||||
emit(JobsStateWithJobs(newJobsList)); |
||||
} |
||||
|
||||
void removeJob(String id) { |
||||
final newState = state.removeById(id); |
||||
final newState = (state as JobsStateWithJobs).removeById(id); |
||||
emit(newState); |
||||
} |
||||
|
||||
Future<void> applyAll() async { |
||||
for (var job in state.jobList) { |
||||
if (job is CreateUserJob) { |
||||
// await api.createUser(job.user); |
||||
if (state is JobsStateWithJobs) { |
||||
var jobs = (state as JobsStateWithJobs).jobList; |
||||
emit(JobsStateLoading()); |
||||
|
||||
var newUsers = <User>[]; |
||||
for (var job in jobs) { |
||||
if (job is CreateUserJob) { |
||||
newUsers.add(job.user); |
||||
await api.createUser(job.user); |
||||
} |
||||
} |
||||
|
||||
usersCubit.addUsers(newUsers); |
||||
await api.apply(); |
||||
|
||||
emit(JobsStateEmpty()); |
||||
|
||||
getIt<NavigationService>().navigator!.pop(); |
||||
} |
||||
emit(JobsState.emtpy()); |
||||
} |
||||
} |
||||
|
@ -1,25 +1,27 @@ |
||||
part of 'jobs_cubit.dart'; |
||||
|
||||
class JobsState extends Equatable { |
||||
const JobsState(this.jobList); |
||||
|
||||
final List<Job> jobList; |
||||
abstract class JobsState extends Equatable { |
||||
@override |
||||
List<Object?> get props => []; |
||||
} |
||||
|
||||
static JobsState emtpy() => JobsState([]); |
||||
class JobsStateLoading extends JobsState {} |
||||
|
||||
bool get isEmpty => jobList.isEmpty; |
||||
class JobsStateEmpty extends JobsState {} |
||||
|
||||
JobsState addJob(Job job) { |
||||
var newJobsList = [...jobList]; |
||||
newJobsList.add(job); |
||||
return JobsState(newJobsList); |
||||
} |
||||
class JobsStateWithJobs extends JobsState { |
||||
JobsStateWithJobs(this.jobList); |
||||
final List<Job> jobList; |
||||
|
||||
JobsState removeById(String id) { |
||||
var newJobsList = jobList.where((element) => element.id != id).toList(); |
||||
return JobsState(newJobsList); |
||||
|
||||
if (newJobsList.isEmpty) { |
||||
return JobsStateEmpty(); |
||||
} |
||||
return JobsStateWithJobs(newJobsList); |
||||
} |
||||
|
||||
@override |
||||
List<Object> get props => jobList; |
||||
List<Object?> get props => jobList; |
||||
} |
||||
|
@ -0,0 +1,21 @@ |
||||
import 'package:flutter/cupertino.dart'; |
||||
import 'package:flutter/material.dart'; |
||||
import 'package:easy_localization/easy_localization.dart'; |
||||
|
||||
class BrandLoader { |
||||
static horizontal() => _HorizontalLoader(); |
||||
} |
||||
|
||||
class _HorizontalLoader extends StatelessWidget { |
||||
@override |
||||
Widget build(BuildContext context) { |
||||
return Column( |
||||
mainAxisSize: MainAxisSize.min, |
||||
children: [ |
||||
Text('basis.wait'.tr()), |
||||
SizedBox(height: 10), |
||||
LinearProgressIndicator(minHeight: 3), |
||||
], |
||||
); |
||||
} |
||||
} |
@ -0,0 +1,51 @@ |
||||
import 'dart:ui'; |
||||
import 'package:flutter/cupertino.dart'; |
||||
|
||||
extension TextExtension on Text { |
||||
Text withColor(Color color) => Text( |
||||
data!, |
||||
key: this.key, |
||||
strutStyle: this.strutStyle, |
||||
textAlign: this.textAlign, |
||||
textDirection: this.textDirection, |
||||
locale: this.locale, |
||||
softWrap: this.softWrap, |
||||
overflow: this.overflow, |
||||
textScaleFactor: this.textScaleFactor, |
||||
maxLines: this.maxLines, |
||||
semanticsLabel: this.semanticsLabel, |
||||
textWidthBasis: textWidthBasis ?? this.textWidthBasis, |
||||
style: this.style != null |
||||
? this.style!.copyWith(color: color) |
||||
: TextStyle(color: color), |
||||
); |
||||
|
||||
Text copyWith({ |
||||
Key? key, |
||||
StrutStyle? strutStyle, |
||||
TextAlign? textAlign, |
||||
TextDirection? textDirection, |
||||
Locale? locale, |
||||
bool? softWrap, |
||||
TextOverflow? overflow, |
||||
double? textScaleFactor, |
||||
int? maxLines, |
||||
String? semanticsLabel, |
||||
TextWidthBasis? textWidthBasis, |
||||
TextStyle? style, |
||||
}) { |
||||
return Text(data!, |
||||
key: key ?? this.key, |
||||
strutStyle: strutStyle ?? this.strutStyle, |
||||
textAlign: textAlign ?? this.textAlign, |
||||
textDirection: textDirection ?? this.textDirection, |
||||
locale: locale ?? this.locale, |
||||
softWrap: softWrap ?? this.softWrap, |
||||
overflow: overflow ?? this.overflow, |
||||
textScaleFactor: textScaleFactor ?? this.textScaleFactor, |
||||
maxLines: maxLines ?? this.maxLines, |
||||
semanticsLabel: semanticsLabel ?? this.semanticsLabel, |
||||
textWidthBasis: textWidthBasis ?? this.textWidthBasis, |
||||
style: style != null ? this.style?.merge(style) ?? style : this.style); |
||||
} |
||||
} |
Loading…
Reference in new issue