// Copyright (C) 2022 WYATT GROUP // Please see the AUTHORS file for details. // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . import 'package:bloc_layout_example/bloc/example_cubit.dart'; import 'package:bloc_layout_example/components/theme_components.dart'; import 'package:flutter/material.dart'; import 'package:wyatt_bloc_layout/wyatt_bloc_layout.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); // This widget is the root of your application. @override Widget build(BuildContext context) => ComponentTheme( componentThemeWidget: AppThemeComponent.components, child: MaterialApp( title: 'Bloc Layout Example', theme: ThemeData( primarySwatch: Colors.blue, ), home: Scaffold( body: Column( children: [ Expanded( child: Row( children: [ Expanded( child: BlocProvider( create: (_) => ExampleCubit()..run(), child: const ExampleCrudStateManagement(), ), ), Expanded( child: BlocProvider( create: (_) => ExampleCubit()..runList(), child: const ExampleListCrudStateManagement(), ), ), ], ), ), Expanded( child: Row( children: [ Expanded( child: BlocProvider( create: (_) => ExampleCubit()..run(), child: ExampleFrameLayoutCrudConsumer(), ), ), Expanded( child: BlocProvider( create: (_) => ExampleCubit()..runList(), child: ExampleFrameLayoutCrudListConsumer(), ), ), ], ), ), ], ), ), ), ); } class ExampleCrudStateManagement extends CubitScreenCrudItemBase { const ExampleCrudStateManagement({super.key}); @override Widget initialBuilder(BuildContext context, CrudInitial state) => Container(color: Colors.yellow); @override Widget successBuilder(BuildContext context, CrudLoaded state) => Center(child: Text(state.data ?? 'errors')); @override ExampleCubit create(BuildContext context) => ExampleCubit()..run(); } class ExampleListCrudStateManagement extends CubitScreenCrudListBase { const ExampleListCrudStateManagement({super.key}); @override Widget initialBuilder(BuildContext context, CrudInitial state) => Container(color: Colors.green); @override Widget successBuilder(BuildContext context, CrudListLoaded state) => Column( mainAxisAlignment: MainAxisAlignment.center, children: state.data.map((e) => Text(e ?? 'error')).toList(), ); @override ExampleCubit create(BuildContext context) => ExampleCubit()..run(); } class ExampleFrameLayoutCrudConsumer extends FrameLayoutCubitScreenCrudItem { ExampleFrameLayoutCrudConsumer({super.key}) : super( customAppBar: (bar) => bar?.copyWith.title( 'Example Title'.wrap(), ), ); @override Widget successBuilder(BuildContext context, CrudLoaded state) => Center(child: Text(state.data ?? 'errors')); @override ExampleCubit create(BuildContext context) => ExampleCubit()..run(); } class ExampleFrameLayoutCrudListConsumer extends FrameLayoutCubitScreenCrudList { ExampleFrameLayoutCrudListConsumer({super.key}) : super( customAppBar: (bar) => bar?.copyWith.title( 'Example Title'.wrap(), ), ); @override Widget successBuilder(BuildContext context, CrudListLoaded state) => Column( mainAxisAlignment: MainAxisAlignment.center, children: state.data.map((e) => Text(e ?? 'error')).toList(), ); @override ExampleCubit create(BuildContext context) => ExampleCubit()..run(); }