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(),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
name: bloc_layout_example
|
||||
description: A new Flutter project.
|
||||
|
||||
# The following line prevents the package from being accidentally published to
|
||||
# pub.dev using `flutter pub publish`. This is preferred for private packages.
|
||||
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||
|
||||
# The following defines the version and build number for your application.
|
||||
# A version number is three numbers separated by dots, like 1.2.43
|
||||
# followed by an optional build number separated by a +.
|
||||
# Both the version and the builder number may be overridden in flutter
|
||||
# build by specifying --build-name and --build-number, respectively.
|
||||
# In Android, build-name is used as versionName while build-number used as versionCode.
|
||||
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
|
||||
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
|
||||
# Read more about iOS versioning at
|
||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||
version: 1.0.0+1
|
||||
|
||||
environment:
|
||||
sdk: ">=2.17.0 <3.0.0"
|
||||
|
||||
# Dependencies specify other packages that your package needs in order to work.
|
||||
# To automatically upgrade your package dependencies to the latest versions
|
||||
# consider running `flutter pub upgrade --major-versions`. Alternatively,
|
||||
# dependencies can be manually updated by changing the version numbers below to
|
||||
# the latest version available on pub.dev. To see which dependencies have newer
|
||||
# versions available, run `flutter pub outdated`.
|
||||
dependencies:
|
||||
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
|
||||
wyatt_bloc_layout:
|
||||
path: "../"
|
||||
|
||||
dev_dependencies:
|
||||
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
||||
|
||||
wyatt_analysis:
|
||||
git:
|
||||
url: https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages
|
||||
ref: wyatt_analysis-v2.1.0
|
||||
path: packages/wyatt_analysis
|
||||
|
||||
# For information on the generic Dart part of this file, see the
|
||||
# following page: https://dart.dev/tools/pub/pubspec
|
||||
|
||||
|
||||
# The following section is specific to Flutter.
|
||||
flutter:
|
||||
|
||||
# The following line ensures that the Material Icons font is
|
||||
# included with your application, so that you can use the icons in
|
||||
# the material Icons class.
|
||||
uses-material-design: true
|
||||
|
||||
# To add assets to your application, add an assets section, like this:
|
||||
# assets:
|
||||
# - images/a_dot_burr.jpeg
|
||||
# - images/a_dot_ham.jpeg
|
||||
|
||||
# An image asset can refer to one or more resolution-specific "variants", see
|
||||
# https://flutter.dev/assets-and-images/#resolution-aware.
|
||||
|
||||
# For details regarding adding assets from package dependencies, see
|
||||
# https://flutter.dev/assets-and-images/#from-packages
|
||||
|
||||
# To add custom fonts to your application, add a fonts section here,
|
||||
# in this "flutter" section. Each entry in this list should have a
|
||||
# "family" key with the font family name, and a "fonts" key with a
|
||||
# list giving the asset and other descriptors for the font. For
|
||||
# example:
|
||||
# fonts:
|
||||
# - family: Schyler
|
||||
# fonts:
|
||||
# - asset: fonts/Schyler-Regular.ttf
|
||||
# - asset: fonts/Schyler-Italic.ttf
|
||||
# style: italic
|
||||
# - family: Trajan Pro
|
||||
# fonts:
|
||||
# - asset: fonts/TrajanPro.ttf
|
||||
# - asset: fonts/TrajanPro_Bold.ttf
|
||||
# weight: 700
|
||||
#
|
||||
# For details regarding fonts from package dependencies,
|
||||
# see https://flutter.dev/custom-fonts/#from-packages
|
||||
@@ -0,0 +1,15 @@
|
||||
// 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/>.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 917 B |
Binary file not shown.
|
After Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 8.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 5.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
@@ -0,0 +1,58 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
If you are serving your web app in a path other than the root, change the
|
||||
href value below to reflect the base path you are serving from.
|
||||
|
||||
The path provided below has to start and end with a slash "/" in order for
|
||||
it to work correctly.
|
||||
|
||||
For more details:
|
||||
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
|
||||
|
||||
This is a placeholder for base href that will be replaced by the value of
|
||||
the `--base-href` argument provided to `flutter build`.
|
||||
-->
|
||||
<base href="$FLUTTER_BASE_HREF">
|
||||
|
||||
<meta charset="UTF-8">
|
||||
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
|
||||
<meta name="description" content="A new Flutter project.">
|
||||
|
||||
<!-- iOS meta tags & icons -->
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||
<meta name="apple-mobile-web-app-title" content="example">
|
||||
<link rel="apple-touch-icon" href="icons/Icon-192.png">
|
||||
|
||||
<!-- Favicon -->
|
||||
<link rel="icon" type="image/png" href="favicon.png"/>
|
||||
|
||||
<title>example</title>
|
||||
<link rel="manifest" href="manifest.json">
|
||||
|
||||
<script>
|
||||
// The value below is injected by flutter build, do not touch.
|
||||
var serviceWorkerVersion = null;
|
||||
</script>
|
||||
<!-- This script adds the flutter initialization JS code -->
|
||||
<script src="flutter.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
window.addEventListener('load', function(ev) {
|
||||
// Download main.dart.js
|
||||
_flutter.loader.loadEntrypoint({
|
||||
serviceWorker: {
|
||||
serviceWorkerVersion: serviceWorkerVersion,
|
||||
}
|
||||
}).then(function(engineInitializer) {
|
||||
return engineInitializer.initializeEngine();
|
||||
}).then(function(appRunner) {
|
||||
return appRunner.runApp();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "example",
|
||||
"short_name": "example",
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"background_color": "#0175C2",
|
||||
"theme_color": "#0175C2",
|
||||
"description": "A new Flutter project.",
|
||||
"orientation": "portrait-primary",
|
||||
"prefer_related_applications": false,
|
||||
"icons": [
|
||||
{
|
||||
"src": "icons/Icon-192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "icons/Icon-512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "icons/Icon-maskable-192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable"
|
||||
},
|
||||
{
|
||||
"src": "icons/Icon-maskable-512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user