Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Studio Plugin for Bloc Generation #116

Closed
fvisticot opened this issue Feb 26, 2019 · 13 comments
Closed

Android Studio Plugin for Bloc Generation #116

fvisticot opened this issue Feb 26, 2019 · 13 comments
Labels
enhancement New feature or request
Projects

Comments

@fvisticot
Copy link

For Android Studio user, it would be fine to have template for bloc generation.
Is it in your plans ?

@felangel
Copy link
Owner

felangel commented Feb 27, 2019

@fvisticot There is currently support for VSCode and I am planning on extending the extension to create the bloc as well as the states and events.

Not sure when I'll get to Android Studio but you're more than welcome to contribute 😄

Ideally, the Android Studio Plugin functionality should align with the VSCode extension (#118).

Use Uber's RIBs Plugin for reference.

@felangel felangel added the good first issue Good for newcomers label Feb 27, 2019
@felangel felangel added this to To do in bloc Feb 27, 2019
@felangel felangel changed the title Adding an Android studio File template for bloc generation Android Studio Plugin for Bloc Generation Mar 1, 2019
@jorgecoca
Copy link
Collaborator

I have some experience with code templates in IntelliJ... I can work on it ;)

@jorgecoca
Copy link
Collaborator

@felangel we should agree on some conventions first before we do any coding, so we keep the IntelliJ plugin and VS Code in sync. What about?

Files generated (XXX represents the name of your bloc, we will have to sanitize this in the generators to be camelCase on code and snake_case for file names)

  • XXX_bloc.dart
  • XXX_event.dart
  • XXX_state.dart
  • bloc.dart

and contents:

bloc.dart

export 'XXX_bloc.dart';
export 'XXX_event.dart';
export 'XXX_state.dart';

XXX_event.dart

import 'package:equatable/equatable.dart';

abstract class XXXEvent extends Equatable {
  XXXEvent([List props = const []]) : super(props);
}

XXX_state.dart

import 'package:equatable/equatable.dart';

abstract class XXXState extends Equatable {
  XXXState([List props = const []]) : super(props);
}

XXX_bloc.dart

import 'dart:async';

import 'package:bloc/bloc.dart';

class XXXBloc
    extends Bloc<XXXEvent, XXXState> {

  @override
  ResetPasswordUiState get initialState => throw Exception('Complete your initialState');

  @override
  Stream<XXXState> mapEventToState(
      XXXState state, XXXEvent event) async* {
    throw Exception('Complete your mapEventToState');
  }
}

I think that might be all we need, right?

@felangel
Copy link
Owner

felangel commented Mar 2, 2019

@jorgecoca that looks good to me 👍
I’ll let you know if I run into anything we haven’t considered as I make progress on the VSCode extension.

@felangel felangel added enhancement New feature or request and removed good first issue Good for newcomers labels Mar 3, 2019
@felangel felangel moved this from To do to In progress in bloc Mar 3, 2019
@felangel felangel assigned felangel and unassigned felangel Mar 3, 2019
@san4io
Copy link

san4io commented Mar 3, 2019

Hello everyone,
While there is no plugin for android studio you can simply do following:

  • Add bloc template in settings:
    image

  • Add Template text:

import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'dart:async';

class $NAME$Bloc extends Bloc<$NAME$Event, $NAME$State> {
  @override
  $NAME$State get initialState => null;// TODO: initial state
  
  @override
  Stream<$NAME$State> mapEventToState($NAME$State currentState, $NAME$Event event) async* {
    // TODO: implement mapEventToState
  }
}

abstract class $NAME$State extends Equatable {
  $NAME$State([List props = const []]) : super(props);
}

abstract class $NAME$Event extends Equatable {
  $NAME$Event([List props = const []]) : super(props);
}
  • Go back to editor and start typing blo:
    image

  • Hit enter, give NAME for your bloc and you'll have following:
    image

Have a nice day!

@fvisticot
Copy link
Author

Good job,
The solution is working but I think original proposal allowing to generate multiple files with proposed convention will result in better code organisation / evolution

@san4io
Copy link

san4io commented Mar 3, 2019

Good job,
The solution is working but I think original proposal allowing to generate multiple files with proposed convention will result in better code organisation / evolution

Totally agree.
I've posted temporary solution.
But you know how it is... permanent temporary solution 😆

@felangel
Copy link
Owner

felangel commented Mar 3, 2019

@jorgecoca will most likely have the permanent solution done relatively quickly 🎉💯

@jorgecoca
Copy link
Collaborator

By the end of this I hope to have something up and running ;)

@ThinkDigitalSoftware
Copy link

You guys are awesome!

@felangel
Copy link
Owner

felangel commented Mar 9, 2019

@jorgecoca is awesome 🥇

@jorgecoca
Copy link
Collaborator

I opened #148 ;)

@felangel felangel moved this from In progress to Done in bloc Mar 18, 2019
@felangel
Copy link
Owner

merged in #148

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
bloc
  
Done
Development

No branches or pull requests

5 participants