Hugo Pointcheval e76857f118
Some checks failed
continuous-integration/drone/pr Build is failing
feat(layout)!: update layout plugins with new components system
2023-05-02 13:32:52 +02:00

156 lines
5.1 KiB
Dart

// 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 <https://www.gnu.org/licenses/>.
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:flutter_bloc/flutter_bloc.dart';
import 'package:wyatt_bloc_layout/wyatt_bloc_layout.dart';
import 'package:wyatt_crud_bloc/wyatt_crud_bloc.dart';
import 'package:wyatt_ui_components/wyatt_ui_components.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(
data: 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<ExampleCubit, String> {
const ExampleCrudStateManagement({super.key});
@override
Widget initialBuilder(BuildContext context, CrudInitial state) =>
Container(color: Colors.yellow);
@override
Widget successBuilder(BuildContext context, CrudLoaded<String> state) =>
Center(child: Text(state.data ?? 'errors'));
@override
ExampleCubit create(BuildContext context) => ExampleCubit()..run();
}
class ExampleListCrudStateManagement
extends CubitScreenCrudListBase<ExampleCubit, String> {
const ExampleListCrudStateManagement({super.key});
@override
Widget initialBuilder(BuildContext context, CrudInitial state) =>
Container(color: Colors.green);
@override
Widget successBuilder(BuildContext context, CrudListLoaded<String> 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<ExampleCubit, String> {
ExampleFrameLayoutCrudConsumer({super.key})
: super(
customAppBar: (bar) => bar?.copyWith.title(
const TextWrapper('Example Title'),
),
);
@override
Widget successBuilder(BuildContext context, CrudLoaded<String> state) =>
Center(child: Text(state.data ?? 'errors'));
@override
ExampleCubit create(BuildContext context) => ExampleCubit()..run();
}
class ExampleFrameLayoutCrudListConsumer
extends FrameLayoutCubitScreenCrudList<ExampleCubit, String> {
ExampleFrameLayoutCrudListConsumer({super.key})
: super(
customAppBar: (bar) => bar?.copyWith.title(
const TextWrapper('Example Title'),
),
);
@override
Widget successBuilder(BuildContext context, CrudListLoaded<String> state) =>
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: state.data.map((e) => Text(e ?? 'error')).toList(),
);
@override
ExampleCubit create(BuildContext context) => ExampleCubit()..run();
}