"flutter counter app with block library" Code Answer's
You're definitely familiar with the best coding language Dart that developers use to develop their projects and they get all their queries like "flutter counter app with block library" answered properly. Developers are finding an appropriate answer about flutter counter app with block library related to the Dart coding language. By visiting this online portal developers get answers concerning Dart codes question like flutter counter app with block library. Enter your desired code related query in the search bar and get every piece of information about Dart code related question on flutter counter app with block library.
flutter counter app with block library
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
abstract class CounterEvent extends Equatable {
const CounterEvent();
@override
List<Object> get props => [];
}
class IncrementEvent extends CounterEvent {}
class DecrementEvent extends CounterEvent {}
class CounterState extends Equatable {
final int counter;
const CounterState({@required this.counter});
@override
List<Object> get props => [counter];
}
class CounterBloc extends Bloc<CounterEvent, CounterState> {
CounterBloc() : super(CounterState(counter: 0));
@override
Stream<CounterState> mapEventToState(CounterEvent event) async* {
print(event.toString());
if (event is IncrementEvent) {
print("inc");
yield CounterState(counter: state.counter + 1);
} else if (state is DecrementEvent) {
yield CounterState(counter: state.counter - 1);
}
}
}
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: BlocProvider<CounterBloc>(
create: (context) => CounterBloc(),
child: Home(
title: "test",
),
),
);
}
}
class Home extends StatefulWidget {
Home({Key key, this.title}) : super(key: key);
final String title;
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
@override
Widget build(BuildContext context) {
final CounterBloc counterBloc = BlocProvider.of<CounterBloc>(context);
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: BlocBuilder<CounterBloc, CounterState>(
//cubit: counterBloc,
builder: (context, state) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
state.counter.toString(),
style: Theme.of(context).textTheme.headline4,
),
],
),
);
},
),
floatingActionButton: FloatingActionButton(
onPressed: () {
print("click");
counterBloc.add(IncrementEvent());
},
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
Source: stackoverflow.com
All those coders who are working on the Dart based application and are stuck on flutter counter app with block library can get a collection of related answers to their query. Programmers need to enter their query on flutter counter app with block library related to Dart code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about flutter counter app with block library for the programmers working on Dart code while coding their module. Coders are also allowed to rectify already present answers of flutter counter app with block library while working on the Dart language code. Developers can add up suggestions if they deem fit any other answer relating to "flutter counter app with block library". Visit this developer's friendly online web community, CodeProZone, and get your queries like flutter counter app with block library resolved professionally and stay updated to the latest Dart updates.