Skip to content

Instantly share code, notes, and snippets.

View AbhishekDoshi26's full-sized avatar
💙
Flutter

Abhishek Doshi AbhishekDoshi26

💙
Flutter
View GitHub Profile
import 'package:state_notifier/state_notifier.dart';
class CounterService extends StateNotifier<int> {
CounterService(int intialValue) : super(intialValue);
void incrementCounter() {
this.state++;
}
void decrementCounter() {
@AbhishekDoshi26
AbhishekDoshi26 / pubspec.yaml
Created October 5, 2021 11:04
state_notifier_provider example's pubspec.yaml file
name: state_notifier_example
description: A new Flutter project.
publish_to: "none" # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
cupertino_icons: ^1.0.2
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:redux/redux.dart';
import 'package:redux_example/redux_service.dart';
class Home extends StatelessWidget {
Home({Key? key}) : super(key: key);
final store = Store<int>(ReduxActions.counterUpdate, initialState: 0);
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:redux_example/home.dart';
import 'package:redux/redux.dart';
import 'package:redux_example/redux_service.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
enum CounterActions { Increment, Decrement, Reset }
class ReduxActions {
static int counterUpdate(int state, dynamic action) {
if (action == CounterActions.Increment) {
return state + 1;
} else if (action == CounterActions.Decrement) {
return (state - 1).toUnsigned(state.bitLength);
} else if (action == CounterActions.Reset) {
state = 0;
import 'dart:io';
import 'dart:convert';
main(List<String> arguments) {
String data = '';
for (int i = 0; i < 100000; i++) {
data = data + 'Hello world\r\n';
}
//Original Data
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.
# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:meta/meta.dart';
part 'counter_event.dart';
part 'counter_state.dart';
class CounterBloc extends Bloc<CounterEvent, CounterState> {
CounterBloc() : super(CounterDataState(counter: 0)) {
on<InitialCounterEvent>((event, emit) => emit(CounterDataState(counter: 0)));
on<IncrementCounterEvent>((event, emit) => emit(CounterDataState(counter: event.counter + 1)));
import 'package:flutter/material.dart';
import 'main.dart';
class Page2 extends StatefulWidget {
const Page2({Key? key}) : super(key: key);
@override
_Page2State createState() => _Page2State();
}
import 'package:flutter/material.dart';
import 'package:routeaware_example/page2.dart';
import 'main.dart';
class Page1 extends StatefulWidget {
const Page1({Key? key}) : super(key: key);
@override
_Page1State createState() => _Page1State();