import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import '../../logic/cubit/counter_cubit.dart'; import '../../logic/cubit/counter_state.dart'; class ThirdScreen extends StatefulWidget { static const String kThirdScreen = '/third_screen'; final String title; final Color backgroundColor; const ThirdScreen({super.key, required this.title,required this.backgroundColor}); @override State createState() => _ThirdScreenState(); } class _ThirdScreenState extends State { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: widget.backgroundColor, title: Text(widget.title), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ const Text( 'You have pushed the button this many times:', ), BlocConsumer( builder: (BuildContext context, state) => Text( '${state.counterValue}', style: Theme.of(context).textTheme.headlineMedium, ), listener: (context, state) { if (state.wasIncremented) { ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text('Incremented'), ), snackBarAnimationStyle: AnimationStyle( duration: Duration(milliseconds: 50), ), ); } else { ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text('Decremented'), ), snackBarAnimationStyle: AnimationStyle( duration: Duration(milliseconds: 50), ), ); } }, ), Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ FloatingActionButton( onPressed: () => BlocProvider.of(context).decrement(), child: Icon(Icons.remove), ), FloatingActionButton( onPressed: () => BlocProvider.of(context).increment(), child: Icon(Icons.add), ) ], ) ], ), ), // This trailing comma makes auto-formatting nicer for build methods. ); } }