Skip to content

Instantly share code, notes, and snippets.

import 'dart:async';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart';
class InheritedNetworkHandler extends InheritedWidget {
final bool isNetworkAvailable;
const InheritedNetworkHandler(
{required this.isNetworkAvailable, required Widget child})
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
// Option 1
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
Future<void> _getDeviceModel() async {
String _model;
try {
// 1
final String result = await platformChannel.invokeMethod('getDeviceModel');
// 2
_model = result;
Future<void> _getDeviceModel() async {
String _model;
try {
// 1
final String result = await platformChannel.invokeMethod('getDeviceModel');
// 2
_model = result;
Future<void> _getDeviceModel() async {
String _model;
try {
// 1
_model = await platformChannel.invokeMethod('getDeviceModel');
} catch (e) {
// 2
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 {
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> {
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
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.
* */