flutter_custom_bloc 0.0.1 flutter_custom_bloc: ^0.0.1 copied to clipboard
The Flutter Custom BLoC Library offers a lightweight implementation of the BLoC pattern for efficient state management in Flutter applications. By utilizing Dart's streams, it separates business logic [...]
import 'package:example/counter_example/bloc/counter_bloc.dart';
import 'package:example/counter_example/ui/counter_screen.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
CounterBloc counterBloc = CounterBloc();
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CustomTextButton(
text: "Counter Example",
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const CounterScreen(),
),
);
},
),
],
),
);
}
}
class CustomTextButton extends StatelessWidget {
final String text;
final VoidCallback onPressed;
const CustomTextButton({
super.key,
required this.text,
required this.onPressed,
});
@override
Widget build(BuildContext context) {
return InkWell(
onTap: onPressed,
child: Container(
padding: const EdgeInsets.all(8),
margin: const EdgeInsets.all(12),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Colors.deepPurple,
),
child: Text(
text,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
);
}
}