Untitled
unknown
dart
2 years ago
2.7 kB
3
Indexable
import 'package:app_wide_state_bloc/blocs/third_screen/cubit/third_screen_cubit.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; class ThirdScreen extends StatefulWidget { static const routeName = "/third-screen"; const ThirdScreen({super.key}); @override State<ThirdScreen> createState() => _ThirdScreenState(); } class _ThirdScreenState extends State<ThirdScreen> { @override Widget build(BuildContext context) { return BlocProvider( create: (context) => ThirdScreenCubit(), child: BlocBuilder<ThirdScreenCubit, ThirdScreenState>( builder: (context, state) { if (state is ThirdScreenShowNumberState) { return Scaffold( appBar: AppBar(), body: Center( child: Column(children: [ Text("${state.value}"), IconButton( onPressed: () => increment(context), icon: const Icon(Icons.add)), IconButton( onPressed: () => decrement(context), icon: const Icon(Icons.remove)), ]), ), ); } else if (state is ThirdScreenInitial) { return Scaffold( appBar: AppBar(), body: Center( child: Column(children: [ const Text("APP"), IconButton( onPressed: () => increment(context), icon: const Icon(Icons.add)), IconButton( onPressed: () => decrement(context), icon: const Icon(Icons.remove)), ]), ), ); } else { return Scaffold( appBar: AppBar(), body: Center( child: Column(children: [ const Text("STATE ERROR"), IconButton( onPressed: () => increment(context), icon: const Icon(Icons.add)), IconButton( onPressed: () => decrement(context), icon: const Icon(Icons.remove)), ]), ), ); } }, ), ); } // ! Functions void decrement(BuildContext context) { BlocProvider.of<ThirdScreenCubit>(context).decrementValue(); } void increment(BuildContext context) { BlocProvider.of<ThirdScreenCubit>(context).incrementValue(); } // * ----------------- }
Editor is loading...