mirror of
https://github.com/flutter/samples.git
synced 2025-11-10 23:08:59 +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:
99
experimental/date_planner/lib/event_list.dart
Normal file
99
experimental/date_planner/lib/event_list.dart
Normal file
@@ -0,0 +1,99 @@
|
||||
// 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 'package:provider/provider.dart';
|
||||
|
||||
import 'event.dart';
|
||||
import 'event_data.dart';
|
||||
import 'event_editor.dart';
|
||||
import 'event_row.dart';
|
||||
|
||||
class EventList extends StatelessWidget {
|
||||
const EventList({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<EventData>(
|
||||
builder: (BuildContext context, EventData events, Widget? child) {
|
||||
return CupertinoPageScaffold(
|
||||
// TODO(mit-mit): Avoid having to pass nav bar manually.
|
||||
//
|
||||
// Would like to pass nav bar and body to CupertinoPageScaffold
|
||||
// directly, similar to the Material Scaffold's `appBar` and `body`
|
||||
// args.
|
||||
// https://github.com/flutter/flutter/issues/149625
|
||||
child: CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
CupertinoSliverNavigationBar(
|
||||
largeTitle: const Text('Date Planner'),
|
||||
trailing: CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
child: const Icon(CupertinoIcons.plus),
|
||||
onPressed: () async {
|
||||
// Issue: Should go to a sheet, not a a full-screen page.
|
||||
// Blocked on https://github.com/flutter/flutter/issues/42560.
|
||||
Event? newEvent = await Navigator.of(context).push(
|
||||
CupertinoPageRoute<Event>(
|
||||
builder: (_) => EventEditor(
|
||||
event: Event(title: 'New event'),
|
||||
isNew: true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (newEvent != null) {
|
||||
events.add(newEvent);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
SliverList.list(
|
||||
children: [
|
||||
for (Period p in Period.values)
|
||||
CupertinoListSection(
|
||||
header: Text(
|
||||
p.name.toUpperCase(),
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
children: [
|
||||
for (Event e in events.sorted(p))
|
||||
// TODO: Support swipe action for deleting.
|
||||
// Should probably use Dismissable?
|
||||
// https://api.flutter.dev/flutter/widgets/Dismissible-class.html
|
||||
EventRow(
|
||||
event: e,
|
||||
onTap: () async {
|
||||
Event? updatedEvent =
|
||||
await Navigator.of(context).push(
|
||||
CupertinoPageRoute<Event>(
|
||||
builder: (_) => EventEditor(
|
||||
event: e.copy(),
|
||||
isNew: false,
|
||||
),
|
||||
),
|
||||
);
|
||||
if (updatedEvent == null) {
|
||||
// The editor passes back null when it deleted
|
||||
// the element.
|
||||
events.delete(e);
|
||||
} else {
|
||||
events.update(e, updatedEvent);
|
||||
}
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user