Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve coffee maker demo example #217

Merged
merged 4 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,65 +71,74 @@ class _AddWaterScreenContent extends StatelessWidget {
height: 200,
width: double.infinity,
),
Padding(
padding:
const EdgeInsets.all(16.0) + const EdgeInsets.only(bottom: 200),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Add water to the coffee',
style: Theme.of(context).textTheme.headlineSmall!.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16),
Text(
'Enter the details to see the quality of the water you are adding to the coffee maker.',
style: Theme.of(context).textTheme.bodyLarge,
),
const SizedBox(height: 24),
AppTextFormField(
controller: TextEditingController(),
textInputType:
const TextInputType.numberWithOptions(decimal: true),
onChanged: onWaterQuantityUpdated,
onSubmitted: onWaterQuantityUpdated,
inputFormatters: [
/* Don't allow minus or space */
FilteringTextInputFormatter.deny(RegExp(r'(\s|-+)')),
],
labelText: 'Water quantity (ml)',
),
const SizedBox(height: 16),
AppTextFormField(
controller: TextEditingController(),
textInputType:
const TextInputType.numberWithOptions(decimal: true),
onChanged: onWaterTemperatureUpdated,
onSubmitted: onWaterTemperatureUpdated,
inputFormatters: [
/* Don't allow minus or space */
FilteringTextInputFormatter.deny(RegExp(r'(\s|-+)')),
],
labelText: 'Water temperature (°C)',
),
WoltSelectionList<WaterSource>.singleSelect(
tilePadding:
const EdgeInsetsDirectional.symmetric(vertical: 8),
itemTileDataGroup: WoltSelectionListItemDataGroup(
group: WaterSource.values
.map(
(e) => WoltSelectionListItemData(
title: e.label, value: e, isSelected: false),
)
.toList(),
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 600),
child: Padding(
padding: const EdgeInsets.all(16.0) +
const EdgeInsets.only(bottom: 200),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Add water to the coffee',
style: Theme.of(context).textTheme.headlineSmall!.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16),
Text(
'Enter the details to see the quality of the water you are adding to the coffee maker.',
style: Theme.of(context).textTheme.bodyLarge,
),
const SizedBox(height: 24),
AppTextFormField(
controller: TextEditingController(),
textInputType:
const TextInputType.numberWithOptions(decimal: true),
onChanged: onWaterQuantityUpdated,
onSubmitted: onWaterQuantityUpdated,
inputFormatters: [
/* Don't allow minus or space */
FilteringTextInputFormatter.deny(RegExp(r'(\s|-+)')),
],
labelText: 'Water quantity (ml)',
),
const SizedBox(height: 16),
AppTextFormField(
controller: TextEditingController(),
textInputType:
const TextInputType.numberWithOptions(decimal: true),
onChanged: onWaterTemperatureUpdated,
onSubmitted: onWaterTemperatureUpdated,
inputFormatters: [
/* Don't allow minus or space */
FilteringTextInputFormatter.deny(RegExp(r'(\s|-+)')),
],
labelText: 'Water temperature (°C)',
),
const SizedBox(height: 24),
Text(
'Select the water source:',
style: Theme.of(context).textTheme.titleMedium,
),
onSelectionUpdateInSingleSelectionList: (item) {
onWaterSourceUpdated(item.value);
},
)
],
const SizedBox(height: 8),
WoltSelectionList<WaterSource>.singleSelect(
tilePadding:
const EdgeInsetsDirectional.symmetric(vertical: 8),
itemTileDataGroup: WoltSelectionListItemDataGroup(
group: WaterSource.values
.map(
(e) => WoltSelectionListItemData(
title: e.label, value: e, isSelected: false),
)
.toList(),
),
onSelectionUpdateInSingleSelectionList: (item) {
onWaterSourceUpdated(item.value);
},
)
],
),
),
),
],
Expand Down Expand Up @@ -169,43 +178,46 @@ class _AddWaterScreenFooter extends StatelessWidget {
Widget build(BuildContext context) {
return Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.all(16.0) +
EdgeInsets.only(bottom: MediaQuery.paddingOf(context).bottom),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ValueListenableBuilder<String?>(
valueListenable: errorMessage,
builder: (_, message, __) {
return message == null
? const SizedBox.shrink()
: Padding(
padding: const EdgeInsets.only(bottom: 12.0),
child: _ErrorNotificationWidget(message),
);
}),
WoltElevatedButton(
onPressed: () {
context.read<AddWaterViewModel>().checkValidity();
},
child: const Text('Check '),
),
const SizedBox(height: 12),
ValueListenableBuilder<bool>(
valueListenable: isReadyToAddWater,
builder: (_, isEnabled, __) {
return WoltElevatedButton(
enabled: isEnabled,
onPressed: () {
context.read<AddWaterViewModel>().addWater();
context.read<RouterViewModel>().onAddWaterStepCompleted();
},
child: const Text('Add water'),
);
},
),
],
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 600),
child: Padding(
padding: const EdgeInsets.all(16.0) +
EdgeInsets.only(bottom: MediaQuery.paddingOf(context).bottom),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ValueListenableBuilder<String?>(
valueListenable: errorMessage,
builder: (_, message, __) {
return message == null
? const SizedBox.shrink()
: Padding(
padding: const EdgeInsets.only(bottom: 12.0),
child: _ErrorNotificationWidget(message),
);
}),
WoltElevatedButton(
onPressed: () {
context.read<AddWaterViewModel>().checkValidity();
},
child: const Text('Check '),
),
const SizedBox(height: 12),
ValueListenableBuilder<bool>(
valueListenable: isReadyToAddWater,
builder: (_, isEnabled, __) {
return WoltElevatedButton(
enabled: isEnabled,
onPressed: () {
context.read<AddWaterViewModel>().addWater();
context.read<RouterViewModel>().onAddWaterStepCompleted();
},
child: const Text('Add water'),
);
},
),
],
),
),
),
);
Expand Down
64 changes: 35 additions & 29 deletions coffee_maker_navigator_2/lib/ui/auth/view/auth_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,41 @@ class AuthScreen extends StatelessWidget {
builder: (context, _) {
return SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 40),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Image(
image: AssetImage('lib/assets/images/dash_coffee.webp'),
fit: BoxFit.cover,
),
Text('Welcome to Coffee Maker!',
style: textTheme.titleLarge!),
const SizedBox(height: 50),
const AppTextFormField(
labelText: 'Username',
textInputType: TextInputType.emailAddress,
),
const SizedBox(height: 20),
const AppTextFormField(
labelText: 'Password',
obscureText: true,
autocorrect: false,
textInputType: TextInputType.visiblePassword,
),
const SizedBox(height: 30),
WoltElevatedButton(
onPressed: () => context
.read<AuthScreenViewModel>()
.logIn('email', 'password'),
child: const Text('Sign in'),
),
],
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 400),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Image(
image:
AssetImage('lib/assets/images/dash_coffee.webp'),
fit: BoxFit.cover,
height: 216,
width: 384,
),
Text('Welcome to Coffee Maker!',
style: textTheme.titleLarge!),
const SizedBox(height: 50),
const AppTextFormField(
labelText: 'Username',
textInputType: TextInputType.emailAddress,
),
const SizedBox(height: 20),
const AppTextFormField(
labelText: 'Password',
obscureText: true,
autocorrect: false,
textInputType: TextInputType.visiblePassword,
),
const SizedBox(height: 30),
WoltElevatedButton(
onPressed: () => context
.read<AuthScreenViewModel>()
.logIn('email', 'password'),
child: const Text('Sign in'),
),
],
),
),
);
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,57 @@
import 'package:coffee_maker_navigator_2/domain/orders/entities/coffee_maker_step.dart';
import 'package:coffee_maker_navigator_2/ui/orders/view_model/orders_screen_view_model.dart';
import 'package:coffee_maker_navigator_2/ui/router/view_model/router_view_model.dart';
import 'package:demo_ui_components/demo_ui_components.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:wolt_modal_sheet/wolt_modal_sheet.dart';

class GrindOrRejectModalPage {
GrindOrRejectModalPage._();

static WoltModalSheetPage build({required String coffeeOrderId}) {
return WoltModalSheetPage(
stickyActionBar: Padding(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
child: Column(
children: [
Builder(builder: (context) {
return WoltElevatedButton(
onPressed: WoltModalSheet.of(context).showNext,
theme: WoltElevatedButtonTheme.secondary,
colorName: WoltColorName.red,
child: const Text('Reject order'),
);
}),
const SizedBox(height: 8),
Builder(builder: (context) {
final model = context.read<OrdersScreenViewModel>();
return WoltElevatedButton(
onPressed: () {
model.onCoffeeOrderStatusChange(
coffeeOrderId, CoffeeMakerStep.addWater);
Navigator.pop(context);
},
child: const Text('Start grinding'),
);
}),
],
),
),
pageTitle: ModalSheetTitle(
'Are you ready to prepare order $coffeeOrderId?',
textAlign: TextAlign.center,
),
trailingNavBarWidget: const WoltModalSheetCloseButton(),
child: const Padding(
padding: EdgeInsets.only(bottom: (2 * WoltElevatedButton.height) + 48),
child: Padding(
padding: EdgeInsets.all(16.0),
child:
ModalSheetContentText('Accept the order to proceed to grinding'),
),
),
);
}
class GrindOrRejectModalPage extends WoltModalSheetPage {
GrindOrRejectModalPage(
String coffeeOrderId,
void Function(String orderId, CoffeeMakerStep? newStep)
onCoffeeOrderStatusChange,
) : super(
child: const Padding(
padding:
EdgeInsets.only(bottom: (2 * WoltElevatedButton.height) + 48),
child: Padding(
padding: EdgeInsets.all(16.0),
child: ModalSheetContentText(
'Accept the order to proceed to grinding'),
),
),
pageTitle: ModalSheetTitle(
'Are you ready to prepare order $coffeeOrderId?',
textAlign: TextAlign.center,
),
stickyActionBar: Padding(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
child: Column(
children: [
Builder(builder: (context) {
return WoltElevatedButton(
onPressed: WoltModalSheet.of(context).showNext,
theme: WoltElevatedButtonTheme.secondary,
colorName: WoltColorName.red,
child: const Text('Reject order'),
);
}),
const SizedBox(height: 8),
Builder(builder: (context) {
return WoltElevatedButton(
onPressed: () {
onCoffeeOrderStatusChange(
coffeeOrderId, CoffeeMakerStep.addWater);
context.read<RouterViewModel>().onGrindStepExit(
hasStartedGrinding: true,
);
},
child: const Text('Start grinding'),
);
}),
],
),
),
trailingNavBarWidget: const WoltModalSheetCloseButton(),
);
}
Loading