mirror of
https://github.com/flutter/samples.git
synced 2025-11-11 15:28:44 +00:00
Initial date planner app (#2390)
Initial **experimental** date planner iOS sample. ## Pre-launch Checklist - [x] I read the [Flutter Style Guide] _recently_, and have followed its advice. - [x] I signed the [CLA]. - [x] I read the [Contributors Guide]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] 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/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md [Contributors Guide]: https://github.com/flutter/samples/blob/main/CONTRIBUTING.md
This commit is contained in:
157
experimental/date_planner/lib/event_detail.dart
Normal file
157
experimental/date_planner/lib/event_detail.dart
Normal file
@@ -0,0 +1,157 @@
|
||||
// Copyright 2024 The Flutter Authors. 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/cupertino.dart';
|
||||
|
||||
import 'color_options.dart';
|
||||
import 'event.dart';
|
||||
import 'event_task.dart';
|
||||
import 'symbol_editor.dart';
|
||||
import 'task_row.dart';
|
||||
|
||||
class EventDetail extends StatefulWidget {
|
||||
final Event event;
|
||||
final bool isEditing;
|
||||
|
||||
const EventDetail({
|
||||
super.key,
|
||||
required this.event,
|
||||
required this.isEditing,
|
||||
});
|
||||
|
||||
@override
|
||||
State<EventDetail> createState() => _EventDetailState();
|
||||
}
|
||||
|
||||
class _EventDetailState extends State<EventDetail> {
|
||||
final _eventText = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_eventText.text = widget.event.title;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const titleStyle = TextStyle(fontWeight: FontWeight.bold, fontSize: 22);
|
||||
final event = widget.event;
|
||||
|
||||
// TODO(mit-mit): Investigate manual overriding of colors and padding.
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 0, 0),
|
||||
color: CupertinoColors.systemBackground,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
if (widget.isEditing)
|
||||
CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
minSize: 0,
|
||||
onPressed: () {
|
||||
Navigator.of(context)
|
||||
.push(
|
||||
CupertinoPageRoute<(IconData, ColorOptions)?>(
|
||||
builder: (_) => SymbolEditor(
|
||||
event.icon,
|
||||
event.color,
|
||||
),
|
||||
),
|
||||
)
|
||||
.then(
|
||||
((IconData, ColorOptions)? data) {
|
||||
if (data != null) {
|
||||
setState(() {
|
||||
var (icon, color) = data;
|
||||
event.icon = icon;
|
||||
event.color = color;
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
child: Icon(
|
||||
event.icon,
|
||||
size: 28,
|
||||
color: event.color.color,
|
||||
),
|
||||
),
|
||||
if (!widget.isEditing)
|
||||
Icon(
|
||||
event.icon,
|
||||
size: 28,
|
||||
color: event.color.color,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
if (widget.isEditing)
|
||||
Expanded(
|
||||
child: CupertinoTextField(
|
||||
decoration: null,
|
||||
padding: EdgeInsets.zero,
|
||||
style: titleStyle,
|
||||
controller: _eventText,
|
||||
onChanged: (value) => event.title = value,
|
||||
),
|
||||
),
|
||||
if (!widget.isEditing) Text(event.title, style: titleStyle),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
// TODO(mit-mit): Use a widget for picking a date.
|
||||
// Issue: Blocked on not having the right calendar widget:
|
||||
// https://github.com/flutter/flutter/issues/63693
|
||||
Text(event.dateFormated),
|
||||
CupertinoListSection(
|
||||
// TODO(mit-mit): The list of tasks should be left-flush with the date above.
|
||||
margin: EdgeInsets.zero,
|
||||
backgroundColor: CupertinoColors.systemBackground,
|
||||
decoration: null,
|
||||
header: const Text(
|
||||
'Tasks',
|
||||
style: TextStyle(
|
||||
color: CupertinoColors.black,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
children: [
|
||||
for (EventTask t in event.tasks)
|
||||
TaskRow(
|
||||
task: t,
|
||||
isEditing: widget.isEditing,
|
||||
),
|
||||
if (widget.isEditing)
|
||||
// TODO(mit-mit): CupertinoButton with icon support?
|
||||
// Consider if CupertinoButton could support setting
|
||||
// both a label and an icon directly:
|
||||
// https://www.kodeco.com/books/swiftui-cookbook/v1.0/chapters/8-add-an-icon-to-a-button-in-swiftui
|
||||
CupertinoButton(
|
||||
child: const Row(
|
||||
children: [
|
||||
Icon(CupertinoIcons.plus),
|
||||
Text('Add task'),
|
||||
],
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
event.tasks.add(EventTask(text: ''));
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user