feat(bloc_layout): add new package to combine bloc_helper, crud_bloc, ui_components, and ui_layout
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:wyatt_bloc_layout/wyatt_bloc_layout.dart';
|
||||
|
||||
class ExampleCubit extends Cubit<CrudState> {
|
||||
ExampleCubit() : super(CrudInitial());
|
||||
|
||||
FutureOr<void> run() async {
|
||||
while (true) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
emit(CrudLoading());
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
emit(CrudError('Cubit Error'));
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
emit(CrudLoaded<String>('DATA LOADED'));
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
emit(CrudInitial());
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> runList() async {
|
||||
while (true) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
emit(CrudLoading());
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
emit(CrudError('Cubit Error'));
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
emit(CrudListLoaded<String>([
|
||||
'DATA LOADED 1',
|
||||
'DATA LOADED 2',
|
||||
'DATA LOADED 3',
|
||||
'DATA LOADED 4'
|
||||
]));
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
emit(CrudInitial());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wyatt_bloc_layout/wyatt_bloc_layout.dart';
|
||||
|
||||
class AppThemeComponent {
|
||||
static ComponentThemeData get components => ComponentThemeData.raw(
|
||||
appBar: CustomAppBar(),
|
||||
bottomNavigationBar: CustomBottomBar(),
|
||||
loadingWidget: CustomLoadingWidget(),
|
||||
errorWidget: CustomErrorWidget(),
|
||||
);
|
||||
}
|
||||
|
||||
class CustomAppBar extends AppBarComponent {
|
||||
const CustomAppBar({super.title});
|
||||
@override
|
||||
Widget build(BuildContext context) => AppBar(
|
||||
title: Text(title ?? 'Title'),
|
||||
);
|
||||
|
||||
@override
|
||||
AppBarComponent configure({String? title}) => CustomAppBar(
|
||||
title: title ?? this.title,
|
||||
);
|
||||
}
|
||||
|
||||
class CustomBottomBar extends BottomNavigationBarComponent {
|
||||
@override
|
||||
Widget build(BuildContext context) => BottomNavigationBar(
|
||||
items: [
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(
|
||||
Icons.e_mobiledata,
|
||||
),
|
||||
label: 'Icon 1'),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(
|
||||
Icons.do_not_disturb_off,
|
||||
),
|
||||
label: 'Icon 2'),
|
||||
],
|
||||
backgroundColor: Colors.blue,
|
||||
);
|
||||
|
||||
@override
|
||||
BottomNavigationBarComponent configure(
|
||||
{void Function(BuildContext p1, int p2)? onTap,
|
||||
int currentIndex = 0}) =>
|
||||
this;
|
||||
}
|
||||
|
||||
class CustomLoadingWidget extends LoadingWidgetComponent {
|
||||
CustomLoadingWidget({super.color});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) =>
|
||||
Center(child: CircularProgressIndicator(color: color));
|
||||
|
||||
@override
|
||||
LoadingWidgetComponent configure({Color? color}) => CustomLoadingWidget(
|
||||
color: color ?? this.color,
|
||||
);
|
||||
}
|
||||
|
||||
class CustomErrorWidget extends ErrorWidgetComponent {
|
||||
CustomErrorWidget({super.error});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ColoredBox(
|
||||
color: Colors.red,
|
||||
child: Center(child: Text(error ?? 'Error')),
|
||||
);
|
||||
|
||||
@override
|
||||
ErrorWidgetComponent configure({String? error}) => CustomErrorWidget(
|
||||
error: error ?? this.error,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
// 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: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) {
|
||||
return 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: ExampleCrudStateManagement(),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: BlocProvider(
|
||||
create: (_) => ExampleCubit()..runList(),
|
||||
child: ExampleListCrudStateManagement(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: BlocProvider(
|
||||
create: (_) => ExampleCubit()..run(),
|
||||
child: ExampleFrameLayoutCrudConsumer()),
|
||||
),
|
||||
Expanded(
|
||||
child: BlocProvider(
|
||||
create: (_) => ExampleCubit()..runList(),
|
||||
child: ExampleFrameLayoutCrudListConsumer()),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ExampleCrudStateManagement
|
||||
extends CrudCubitConsumerScreen<ExampleCubit, String> {
|
||||
@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'));
|
||||
}
|
||||
|
||||
class ExampleListCrudStateManagement
|
||||
extends CrudListCubitConsumerScreen<ExampleCubit, String> {
|
||||
@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(),
|
||||
);
|
||||
}
|
||||
|
||||
class ExampleFrameLayoutCrudConsumer
|
||||
extends FrameLayoutCrudConsumerScreen<ExampleCubit, String> {
|
||||
const ExampleFrameLayoutCrudConsumer()
|
||||
: super(
|
||||
title: 'Example Title',
|
||||
currentIndex: 0,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget successBuilder(BuildContext context, CrudLoaded<String> state) =>
|
||||
Center(child: Text(state.data ?? 'errors'));
|
||||
}
|
||||
|
||||
class ExampleFrameLayoutCrudListConsumer
|
||||
extends FrameLayoutCrudListConsumerScreen<ExampleCubit, String> {
|
||||
const ExampleFrameLayoutCrudListConsumer()
|
||||
: super(
|
||||
title: 'Example Title',
|
||||
currentIndex: 0,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget successBuilder(BuildContext context, CrudListLoaded<String> state) =>
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: state.data.map((e) => Text(e ?? 'error')).toList(),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user