Sonnat Project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

34 lines
985 B

import 'dart:math';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:sonnat/core/utils/base_cubit_type.dart';
import 'package:sonnat/features/single_post/view_models/comment.dart';
class SinglePostCubit extends Cubit<BaseCubitType<SinglePostState>> {
List<Comment> commentList = [];
SinglePostCubit() : super(BaseCubitType(eventName: SinglePostState.empty));
void empty() => emit(BaseCubitType(eventName: SinglePostState.empty));
void addComment(String comment) {
Comment newComment = Comment(
date: DateTime.now().millisecondsSinceEpoch,
text: comment,
author: 'محسن زمانی',
id: Random.secure().nextInt(10000),
);
commentList.insert(0, newComment);
emit(BaseCubitType(eventName: SinglePostState.data));
}
void deleteComment(int id) {
commentList.removeWhere((element) => element.id == id);
emit(BaseCubitType(eventName: SinglePostState.data));
}
}
enum SinglePostState {
empty,
data,
}