Skip to content

Instantly share code, notes, and snippets.

View felangel's full-sized avatar
coding

Felix Angelov felangel

coding
View GitHub Profile
@felangel
felangel / text_view.dart
Last active September 7, 2018 05:39
[platform_views] TextView
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
typedef void TextViewCreatedCallback(TextViewController controller);
class TextView extends StatefulWidget {
const TextView({
Key key,
@felangel
felangel / TextViewPlugin.java
Created September 7, 2018 05:40
[platform_views] TextViewPlugin
package angelov.felix.textview;
import io.flutter.plugin.common.PluginRegistry.Registrar;
public class TextViewPlugin {
public static void registerWith(Registrar registrar) {
registrar
.platformViewRegistry()
.registerViewFactory(
"plugins.felix.angelov/textview", new TextViewFactory(registrar.messenger()));
@felangel
felangel / TextViewFactory.java
Created September 7, 2018 05:44
[platform_views] TextViewFactory
package angelov.felix.textview;
import android.content.Context;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.StandardMessageCodec;
import io.flutter.plugin.platform.PlatformView;
import io.flutter.plugin.platform.PlatformViewFactory;
public class TextViewFactory extends PlatformViewFactory {
private final BinaryMessenger messenger;
@felangel
felangel / FlutterTextView.java
Created September 7, 2018 05:48
[platform_views] FlutterTextView
package angelov.felix.textview;
import android.content.Context;
import android.view.View;
import android.widget.TextView;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import static io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import static io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.BinaryMessenger;
@felangel
felangel / main.dart
Last active September 7, 2018 06:40
[platform_views] TextViewExample
import 'package:flutter/material.dart';
import 'package:text_view/text_view.dart';
void main() => runApp(MaterialApp(home: TextViewExample()));
class TextViewExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Flutter TextView example')),
@felangel
felangel / simple_bloc.dart
Last active October 14, 2018 08:29
[bloc_package] simple bloc example
import 'dart:async';
import 'package:bloc/bloc.dart';
class SimpleBloc extends Bloc<dynamic, String> {
@override
Stream<String> mapEventToState(String state, dynamic event) async* {
yield 'state';
}
}
@felangel
felangel / login_state.dart
Last active November 5, 2020 11:57
[bloc_package] LoginState
class LoginState {
final bool isLoading;
final bool isLoginButtonEnabled;
final String error;
final String token;
const LoginState({
@required this.isLoading,
@required this.isLoginButtonEnabled,
@required this.error,
@felangel
felangel / login_event.dart
Last active October 9, 2018 04:26
[bloc_package] LoginEvent
abstract class LoginEvent {}
class LoginButtonPressed extends LoginEvent {
final String username;
final String password;
LoginButtonPressed({@required this.username, @required this.password});
}
@felangel
felangel / login_bloc.dart
Last active October 14, 2018 08:30
[bloc_package] LoginBloc
class LoginBloc extends Bloc<LoginEvent, LoginState> {
LoginState get initialState => LoginState.initial();
void onLoginButtonPressed({String username, String password}) {
dispatch(
LoginButtonPressed(
username: username,
password: password,
),
);
@felangel
felangel / login_form.dart
Created October 8, 2018 16:56
[bloc_package] LoginForm
class LoginForm extends StatelessWidget {
final LoginBloc loginBloc;
final usernameController = TextEditingController();
final passwordController = TextEditingController();
const LoginForm({Key key, @required this.loginBloc}): super(key: key);
@override
Widget build(BuildContext context) {
return BlocBuilder<LoginState>(