1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 22:09:06 +00:00
Files
samples/experimental/web_dashboard/lib/src/widgets/edit_entry.dart
Miguel Beltran 18848bdd84 Enable Material 3 in experimental/web_dashboard (#1954)
Enabled Material 3.

Replaced the `ElevatedButton` by `FilledButton` for better contrast.

#### Before Material 3

<img width="1392" alt="Screenshot 2023-07-21 at 15 26 44"
src="https://github.com/flutter/samples/assets/2494376/dea484eb-cb0f-46e1-a6b0-bdfef7bab519">

#### With Material 3

<img width="1392" alt="Screenshot 2023-07-21 at 15 28 22"
src="https://github.com/flutter/samples/assets/2494376/a2a449c1-3a73-4bc0-a270-33b6b9d91fa3">


## Pre-launch Checklist

- [ ] I read the [Flutter Style Guide] _recently_, and have followed its
advice.
- [ ] I signed the [CLA].
- [ ] I read the [Contributors Guide].
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-devrel
channel on [Discord].

<!-- Links -->
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[CLA]: https://cla.developers.google.com/
[Discord]: https://github.com/flutter/flutter/wiki/Chat
[Contributors Guide]:
https://github.com/flutter/samples/blob/main/CONTRIBUTING.md
2023-07-22 09:58:29 +10:00

156 lines
4.5 KiB
Dart

// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:intl/intl.dart' as intl;
import 'package:provider/provider.dart';
import 'package:web_dashboard/src/api/api.dart';
import '../app.dart';
import 'categories_dropdown.dart';
class NewEntryForm extends StatefulWidget {
const NewEntryForm({super.key});
@override
State<NewEntryForm> createState() => _NewEntryFormState();
}
class _NewEntryFormState extends State<NewEntryForm> {
late Category _selected;
final Entry _entry = Entry(0, DateTime.now());
@override
Widget build(BuildContext context) {
var api = Provider.of<AppState>(context).api!;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: CategoryDropdown(
api: api.categories,
onSelected: (category) {
if (category == null) return;
setState(() {
_selected = category;
});
},
),
),
EditEntryForm(
entry: _entry,
onDone: (shouldInsert) {
if (shouldInsert) {
api.entries.insert(_selected.id!, _entry);
}
Navigator.of(context).pop();
},
),
],
);
}
}
class EditEntryForm extends StatefulWidget {
final Entry? entry;
final ValueChanged<bool> onDone;
const EditEntryForm({
required this.entry,
required this.onDone,
super.key,
});
@override
State<EditEntryForm> createState() => _EditEntryFormState();
}
class _EditEntryFormState extends State<EditEntryForm> {
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(8),
child: TextFormField(
initialValue: widget.entry!.value.toString(),
decoration: const InputDecoration(labelText: 'Value'),
keyboardType: TextInputType.number,
validator: (value) {
try {
int.parse(value!);
} catch (e) {
return "Please enter a whole number";
}
return null;
},
onChanged: (newValue) {
widget.entry!.value = int.parse(newValue);
},
),
),
Padding(
padding: const EdgeInsets.all(8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(intl.DateFormat('MM/dd/yyyy').format(widget.entry!.time)),
FilledButton(
child: const Text('Edit'),
onPressed: () async {
var result = await showDatePicker(
context: context,
initialDate: widget.entry!.time,
firstDate:
DateTime.now().subtract(const Duration(days: 365)),
lastDate: DateTime.now());
if (result == null) {
return;
}
setState(() {
widget.entry!.time = result;
});
},
)
],
),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Padding(
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
child: FilledButton(
child: const Text('Cancel'),
onPressed: () {
widget.onDone(false);
},
),
),
Padding(
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
child: FilledButton(
child: const Text('OK'),
onPressed: () {
if (_formKey.currentState!.validate()) {
widget.onDone(true);
}
},
),
),
],
)
],
),
);
}
}