Skip to content

Commit

Permalink
Merge pull request #26 from leancodepl/feat/generic-presentation-even…
Browse files Browse the repository at this point in the history
…t-example
  • Loading branch information
shilangyu authored Aug 30, 2023
2 parents d3de5aa + cfa9021 commit 0b6b1ae
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
6 changes: 3 additions & 3 deletions packages/bloc_presentation/example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.8.21'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip
9 changes: 6 additions & 3 deletions packages/bloc_presentation/example/lib/comment_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import 'dart:math';
import 'package:bloc_presentation/bloc_presentation.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class CommentCubit extends Cubit<CommentState> with BlocPresentationMixin {
class CommentCubit extends Cubit<CommentState>
with BlocPresentationMixin<CommentState, CommentEvent> {
CommentCubit() : super(const CommentInitialState());

void fetch() {
Expand Down Expand Up @@ -32,13 +33,15 @@ class CommentCubit extends Cubit<CommentState> with BlocPresentationMixin {
}
}

class FailedToUpvote implements BlocPresentationEvent {
sealed class CommentEvent {}

class FailedToUpvote implements CommentEvent {
const FailedToUpvote(this.reason);

final String reason;
}

class SuccessfulUpvote implements BlocPresentationEvent {
class SuccessfulUpvote implements CommentEvent {
const SuccessfulUpvote(this.message);

final String message;
Expand Down
19 changes: 10 additions & 9 deletions packages/bloc_presentation/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ class MyHomePage extends StatelessWidget {

@override
Widget build(BuildContext context) {
return BlocPresentationListener<CommentCubit>(
return BlocPresentationListener<CommentCubit, CommentEvent>(
listener: (context, event) {
// we know we will receive this event once
if (event is FailedToUpvote) {
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(SnackBar(content: Text(event.reason)));
} else if (event is SuccessfulUpvote) {
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(SnackBar(content: Text(event.message)));
switch (event) {
case FailedToUpvote():
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(SnackBar(content: Text(event.reason)));
case SuccessfulUpvote():
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(SnackBar(content: Text(event.message)));
}
},
child: Scaffold(
Expand Down
2 changes: 1 addition & 1 deletion packages/bloc_presentation/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dev_dependencies:
bloc_test: ^9.1.2
flutter_test:
sdk: flutter
leancode_lint: '^5.0.0'
leancode_lint: ^6.0.0

flutter:
uses-material-design: true

0 comments on commit 0b6b1ae

Please sign in to comment.