Skip to content

Instantly share code, notes, and snippets.

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_blocs_testing/bloc_tutorial/bloc/login_bloc.dart';
class LoginScreen extends StatelessWidget {
const LoginScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
TextButton(
onPressed: () {
context.read<LoginBloc>().add(LoginButtonTappedEvent());
},
child: const Text("Tap me!!!"),
)
Widget _prepareLoginScreen() {
return BlocProvider(
create: (BuildContext context) {
return LoginBloc();
},
child: const LoginScreen(),
);
}
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class LoginScreen extends StatelessWidget {
const LoginScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Login")),
part of 'login_bloc.dart';
// This is also an abstract class
// which can be again extended by other classes
/*
* The reason for having a one base class is because,
* We can refer it for all other child class,
* throughout other files where it is used.
* */
part of 'login_bloc.dart';
// It's a simple abstract class
// which can be extended for other event's
abstract class LoginEvent {
const LoginEvent();
}
/*
Will be used later
import 'package:bloc/bloc.dart';
part 'login_event.dart';
part 'login_state.dart';
/*
We extend the the Bloc class and also mention the
type for event and state.
*/
class LoginBloc extends Bloc<LoginEvent, LoginState> {
import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
Future<void> _getDeviceModel() async {
String _model;
try {
// 1
_model = await platformChannel.invokeMethod('getDeviceModel');
} catch (e) {
// 2