mirror of
https://github.com/flutter/samples.git
synced 2025-11-11 23:39:14 +00:00
[Gallery] Fix directory structure (#312)
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// Copyright 2019 The Flutter team. 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:gallery/l10n/gallery_localizations.dart';
|
||||
|
||||
// BEGIN cupertinoActivityIndicatorDemo
|
||||
|
||||
class CupertinoProgressIndicatorDemo extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
automaticallyImplyLeading: false,
|
||||
middle: Text(
|
||||
GalleryLocalizations.of(context).demoCupertinoActivityIndicatorTitle,
|
||||
),
|
||||
),
|
||||
child: const Center(
|
||||
child: CupertinoActivityIndicator(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// END
|
||||
342
gallery/lib/demos/cupertino/cupertino_alert_demo.dart
Normal file
342
gallery/lib/demos/cupertino/cupertino_alert_demo.dart
Normal file
@@ -0,0 +1,342 @@
|
||||
// Copyright 2019 The Flutter team. 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:gallery/data/gallery_options.dart';
|
||||
import 'package:gallery/l10n/gallery_localizations.dart';
|
||||
|
||||
// BEGIN cupertinoAlertDemo
|
||||
|
||||
enum AlertDemoType {
|
||||
alert,
|
||||
alertTitle,
|
||||
alertButtons,
|
||||
alertButtonsOnly,
|
||||
actionSheet,
|
||||
}
|
||||
|
||||
class CupertinoAlertDemo extends StatefulWidget {
|
||||
const CupertinoAlertDemo({
|
||||
Key key,
|
||||
@required this.type,
|
||||
}) : super(key: key);
|
||||
|
||||
final AlertDemoType type;
|
||||
|
||||
@override
|
||||
_CupertinoAlertDemoState createState() => _CupertinoAlertDemoState();
|
||||
}
|
||||
|
||||
class _CupertinoAlertDemoState extends State<CupertinoAlertDemo> {
|
||||
String lastSelectedValue;
|
||||
|
||||
String _title(BuildContext context) {
|
||||
switch (widget.type) {
|
||||
case AlertDemoType.alert:
|
||||
return GalleryLocalizations.of(context).demoCupertinoAlertTitle;
|
||||
case AlertDemoType.alertTitle:
|
||||
return GalleryLocalizations.of(context)
|
||||
.demoCupertinoAlertWithTitleTitle;
|
||||
case AlertDemoType.alertButtons:
|
||||
return GalleryLocalizations.of(context).demoCupertinoAlertButtonsTitle;
|
||||
case AlertDemoType.alertButtonsOnly:
|
||||
return GalleryLocalizations.of(context)
|
||||
.demoCupertinoAlertButtonsOnlyTitle;
|
||||
case AlertDemoType.actionSheet:
|
||||
return GalleryLocalizations.of(context).demoCupertinoActionSheetTitle;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
void _showDemoDialog({BuildContext context, Widget child}) {
|
||||
showCupertinoDialog<String>(
|
||||
context: context,
|
||||
builder: (context) => ApplyTextOptions(child: child),
|
||||
).then((value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
lastSelectedValue = value;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _showDemoActionSheet({BuildContext context, Widget child}) {
|
||||
child = ApplyTextOptions(
|
||||
child: CupertinoTheme(
|
||||
data: CupertinoTheme.of(context),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
showCupertinoModalPopup<String>(
|
||||
context: context,
|
||||
builder: (context) => child,
|
||||
).then((value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
lastSelectedValue = value;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _onAlertPress(BuildContext context) {
|
||||
_showDemoDialog(
|
||||
context: context,
|
||||
child: CupertinoAlertDialog(
|
||||
title: Text(GalleryLocalizations.of(context).dialogDiscardTitle),
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
child: Text(
|
||||
GalleryLocalizations.of(context).cupertinoAlertDiscard,
|
||||
),
|
||||
isDestructiveAction: true,
|
||||
onPressed: () => Navigator.of(context, rootNavigator: true).pop(
|
||||
GalleryLocalizations.of(context).cupertinoAlertDiscard,
|
||||
),
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
child: Text(
|
||||
GalleryLocalizations.of(context).cupertinoAlertCancel,
|
||||
),
|
||||
isDefaultAction: true,
|
||||
onPressed: () => Navigator.of(context, rootNavigator: true).pop(
|
||||
GalleryLocalizations.of(context).cupertinoAlertCancel,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onAlertWithTitlePress(BuildContext context) {
|
||||
_showDemoDialog(
|
||||
context: context,
|
||||
child: CupertinoAlertDialog(
|
||||
title: Text(
|
||||
GalleryLocalizations.of(context).cupertinoAlertLocationTitle,
|
||||
),
|
||||
content: Text(
|
||||
GalleryLocalizations.of(context).cupertinoAlertLocationDescription,
|
||||
),
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
child: Text(
|
||||
GalleryLocalizations.of(context).cupertinoAlertDontAllow,
|
||||
),
|
||||
onPressed: () => Navigator.of(context, rootNavigator: true).pop(
|
||||
GalleryLocalizations.of(context).cupertinoAlertDontAllow,
|
||||
),
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
child: Text(
|
||||
GalleryLocalizations.of(context).cupertinoAlertAllow,
|
||||
),
|
||||
onPressed: () => Navigator.of(context, rootNavigator: true).pop(
|
||||
GalleryLocalizations.of(context).cupertinoAlertAllow,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onAlertWithButtonsPress(BuildContext context) {
|
||||
_showDemoDialog(
|
||||
context: context,
|
||||
child: CupertinoDessertDialog(
|
||||
title: Text(
|
||||
GalleryLocalizations.of(context).cupertinoAlertFavoriteDessert,
|
||||
),
|
||||
content: Text(
|
||||
GalleryLocalizations.of(context).cupertinoAlertDessertDescription,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onAlertButtonsOnlyPress(BuildContext context) {
|
||||
_showDemoDialog(
|
||||
context: context,
|
||||
child: const CupertinoDessertDialog(),
|
||||
);
|
||||
}
|
||||
|
||||
void _onActionSheetPress(BuildContext context) {
|
||||
_showDemoActionSheet(
|
||||
context: context,
|
||||
child: CupertinoActionSheet(
|
||||
title: Text(
|
||||
GalleryLocalizations.of(context).cupertinoAlertFavoriteDessert,
|
||||
),
|
||||
message: Text(
|
||||
GalleryLocalizations.of(context).cupertinoAlertDessertDescription,
|
||||
),
|
||||
actions: [
|
||||
CupertinoActionSheetAction(
|
||||
child: Text(
|
||||
GalleryLocalizations.of(context).cupertinoAlertCheesecake,
|
||||
),
|
||||
onPressed: () => Navigator.of(context, rootNavigator: true).pop(
|
||||
GalleryLocalizations.of(context).cupertinoAlertCheesecake,
|
||||
),
|
||||
),
|
||||
CupertinoActionSheetAction(
|
||||
child: Text(
|
||||
GalleryLocalizations.of(context).cupertinoAlertTiramisu,
|
||||
),
|
||||
onPressed: () => Navigator.of(context, rootNavigator: true).pop(
|
||||
GalleryLocalizations.of(context).cupertinoAlertTiramisu,
|
||||
),
|
||||
),
|
||||
CupertinoActionSheetAction(
|
||||
child: Text(
|
||||
GalleryLocalizations.of(context).cupertinoAlertApplePie,
|
||||
),
|
||||
onPressed: () => Navigator.of(context, rootNavigator: true).pop(
|
||||
GalleryLocalizations.of(context).cupertinoAlertApplePie,
|
||||
),
|
||||
),
|
||||
],
|
||||
cancelButton: CupertinoActionSheetAction(
|
||||
child: Text(
|
||||
GalleryLocalizations.of(context).cupertinoAlertCancel,
|
||||
),
|
||||
isDefaultAction: true,
|
||||
onPressed: () => Navigator.of(context, rootNavigator: true).pop(
|
||||
GalleryLocalizations.of(context).cupertinoAlertCancel,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
automaticallyImplyLeading: false,
|
||||
middle: Text(_title(context)),
|
||||
),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: CupertinoButton.filled(
|
||||
child: Text(
|
||||
GalleryLocalizations.of(context).cupertinoShowAlert,
|
||||
),
|
||||
onPressed: () {
|
||||
switch (widget.type) {
|
||||
case AlertDemoType.alert:
|
||||
_onAlertPress(context);
|
||||
break;
|
||||
case AlertDemoType.alertTitle:
|
||||
_onAlertWithTitlePress(context);
|
||||
break;
|
||||
case AlertDemoType.alertButtons:
|
||||
_onAlertWithButtonsPress(context);
|
||||
break;
|
||||
case AlertDemoType.alertButtonsOnly:
|
||||
_onAlertButtonsOnlyPress(context);
|
||||
break;
|
||||
case AlertDemoType.actionSheet:
|
||||
_onActionSheetPress(context);
|
||||
break;
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
if (lastSelectedValue != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Text(
|
||||
GalleryLocalizations.of(context)
|
||||
.dialogSelectedOption(lastSelectedValue),
|
||||
style: CupertinoTheme.of(context).textTheme.textStyle,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CupertinoDessertDialog extends StatelessWidget {
|
||||
const CupertinoDessertDialog({Key key, this.title, this.content})
|
||||
: super(key: key);
|
||||
|
||||
final Widget title;
|
||||
final Widget content;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoAlertDialog(
|
||||
title: title,
|
||||
content: content,
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
child: Text(
|
||||
GalleryLocalizations.of(context).cupertinoAlertCheesecake,
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(context, rootNavigator: true).pop(
|
||||
GalleryLocalizations.of(context).cupertinoAlertCheesecake,
|
||||
);
|
||||
},
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
child: Text(
|
||||
GalleryLocalizations.of(context).cupertinoAlertTiramisu,
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(context, rootNavigator: true).pop(
|
||||
GalleryLocalizations.of(context).cupertinoAlertTiramisu,
|
||||
);
|
||||
},
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
child: Text(
|
||||
GalleryLocalizations.of(context).cupertinoAlertApplePie,
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(context, rootNavigator: true).pop(
|
||||
GalleryLocalizations.of(context).cupertinoAlertApplePie,
|
||||
);
|
||||
},
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
child: Text(
|
||||
GalleryLocalizations.of(context).cupertinoAlertChocolateBrownie,
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(context, rootNavigator: true).pop(
|
||||
GalleryLocalizations.of(context).cupertinoAlertChocolateBrownie,
|
||||
);
|
||||
},
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
child: Text(
|
||||
GalleryLocalizations.of(context).cupertinoAlertCancel,
|
||||
),
|
||||
isDestructiveAction: true,
|
||||
onPressed: () {
|
||||
Navigator.of(context, rootNavigator: true).pop(
|
||||
GalleryLocalizations.of(context).cupertinoAlertCancel,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// END
|
||||
44
gallery/lib/demos/cupertino/cupertino_button_demo.dart
Normal file
44
gallery/lib/demos/cupertino/cupertino_button_demo.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright 2019 The Flutter team. 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:gallery/l10n/gallery_localizations.dart';
|
||||
|
||||
// BEGIN cupertinoButtonDemo
|
||||
|
||||
class CupertinoButtonDemo extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
automaticallyImplyLeading: false,
|
||||
middle:
|
||||
Text(GalleryLocalizations.of(context).demoCupertinoButtonsTitle),
|
||||
),
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
CupertinoButton(
|
||||
child: Text(
|
||||
GalleryLocalizations.of(context).cupertinoButton,
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
CupertinoButton.filled(
|
||||
child: Text(
|
||||
GalleryLocalizations.of(context).cupertinoButtonWithBackground,
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// END
|
||||
@@ -0,0 +1,82 @@
|
||||
// Copyright 2019 The Flutter team. 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:flutter/material.dart';
|
||||
import 'package:gallery/l10n/gallery_localizations.dart';
|
||||
|
||||
// BEGIN cupertinoNavigationBarDemo
|
||||
|
||||
class CupertinoNavigationBarDemo extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Navigator(onGenerateRoute: (settings) {
|
||||
return _NoAnimationCupertinoPageRoute<void>(
|
||||
title: GalleryLocalizations.of(context).demoCupertinoNavigationBarTitle,
|
||||
builder: (context) => CupertinoPageScaffold(
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
CupertinoSliverNavigationBar(
|
||||
automaticallyImplyLeading: false,
|
||||
),
|
||||
SliverPadding(
|
||||
padding: MediaQuery.of(context)
|
||||
.removePadding(removeTop: true)
|
||||
.padding,
|
||||
sliver: SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
final title = GalleryLocalizations.of(context)
|
||||
.starterAppDrawerItem(index + 1);
|
||||
return ListTile(
|
||||
onTap: () {
|
||||
Navigator.of(context).push(CupertinoPageRoute<void>(
|
||||
title: title,
|
||||
builder: (context) => _SecondPage(),
|
||||
));
|
||||
},
|
||||
title: Text(title),
|
||||
);
|
||||
},
|
||||
childCount: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class _SecondPage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(),
|
||||
child: Container(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A CupertinoPageRoute without any transition animations.
|
||||
class _NoAnimationCupertinoPageRoute<T> extends CupertinoPageRoute<T> {
|
||||
_NoAnimationCupertinoPageRoute({
|
||||
@required WidgetBuilder builder,
|
||||
String title,
|
||||
}) : super(builder: builder, title: title);
|
||||
|
||||
@override
|
||||
Widget buildTransitions(
|
||||
BuildContext context,
|
||||
Animation<double> animation,
|
||||
Animation<double> secondaryAnimation,
|
||||
Widget child,
|
||||
) {
|
||||
return child;
|
||||
}
|
||||
}
|
||||
|
||||
// END
|
||||
241
gallery/lib/demos/cupertino/cupertino_picker_demo.dart
Normal file
241
gallery/lib/demos/cupertino/cupertino_picker_demo.dart
Normal file
@@ -0,0 +1,241 @@
|
||||
// Copyright 2019 The Flutter team. 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:gallery/l10n/gallery_localizations.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
// BEGIN cupertinoPickersDemo
|
||||
|
||||
class CupertinoPickerDemo extends StatefulWidget {
|
||||
@override
|
||||
_CupertinoPickerDemoState createState() => _CupertinoPickerDemoState();
|
||||
}
|
||||
|
||||
class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> {
|
||||
Duration timer = const Duration();
|
||||
|
||||
// Value that is shown in the date picker in date mode.
|
||||
DateTime date = DateTime.now();
|
||||
|
||||
// Value that is shown in the date picker in time mode.
|
||||
DateTime time = DateTime.now();
|
||||
|
||||
// Value that is shown in the date picker in dateAndTime mode.
|
||||
DateTime dateTime = DateTime.now();
|
||||
|
||||
Widget _buildDatePicker(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
showCupertinoModalPopup<void>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return _BottomPicker(
|
||||
child: CupertinoDatePicker(
|
||||
backgroundColor:
|
||||
CupertinoColors.systemBackground.resolveFrom(context),
|
||||
mode: CupertinoDatePickerMode.date,
|
||||
initialDateTime: date,
|
||||
onDateTimeChanged: (newDateTime) {
|
||||
setState(() => date = newDateTime);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
child: _Menu(children: [
|
||||
Text(GalleryLocalizations.of(context).demoCupertinoPickerDate),
|
||||
Text(
|
||||
DateFormat.yMMMMd().format(date),
|
||||
style: TextStyle(color: CupertinoColors.inactiveGray),
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTimePicker(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
showCupertinoModalPopup<void>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return _BottomPicker(
|
||||
child: CupertinoDatePicker(
|
||||
backgroundColor:
|
||||
CupertinoColors.systemBackground.resolveFrom(context),
|
||||
mode: CupertinoDatePickerMode.time,
|
||||
initialDateTime: time,
|
||||
onDateTimeChanged: (newDateTime) {
|
||||
setState(() => time = newDateTime);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
child: _Menu(
|
||||
children: [
|
||||
Text(GalleryLocalizations.of(context).demoCupertinoPickerTime),
|
||||
Text(
|
||||
DateFormat.jm().format(time),
|
||||
style: TextStyle(color: CupertinoColors.inactiveGray),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDateAndTimePicker(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
showCupertinoModalPopup<void>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return _BottomPicker(
|
||||
child: CupertinoDatePicker(
|
||||
backgroundColor:
|
||||
CupertinoColors.systemBackground.resolveFrom(context),
|
||||
mode: CupertinoDatePickerMode.dateAndTime,
|
||||
initialDateTime: dateTime,
|
||||
onDateTimeChanged: (newDateTime) {
|
||||
setState(() => dateTime = newDateTime);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
child: _Menu(
|
||||
children: [
|
||||
Text(GalleryLocalizations.of(context).demoCupertinoPickerDateTime),
|
||||
Text(
|
||||
DateFormat.yMMMd().add_jm().format(dateTime),
|
||||
style: TextStyle(color: CupertinoColors.inactiveGray),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCountdownTimerPicker(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
showCupertinoModalPopup<void>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return _BottomPicker(
|
||||
child: CupertinoTimerPicker(
|
||||
backgroundColor:
|
||||
CupertinoColors.systemBackground.resolveFrom(context),
|
||||
initialTimerDuration: timer,
|
||||
onTimerDurationChanged: (newTimer) {
|
||||
setState(() => timer = newTimer);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
child: _Menu(
|
||||
children: [
|
||||
Text(GalleryLocalizations.of(context).demoCupertinoPickerTimer),
|
||||
Text(
|
||||
'${timer.inHours}:'
|
||||
'${(timer.inMinutes % 60).toString().padLeft(2, '0')}:'
|
||||
'${(timer.inSeconds % 60).toString().padLeft(2, '0')}',
|
||||
style: TextStyle(color: CupertinoColors.inactiveGray),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
automaticallyImplyLeading: false,
|
||||
middle: Text(GalleryLocalizations.of(context).demoCupertinoPickerTitle),
|
||||
),
|
||||
child: DefaultTextStyle(
|
||||
style: CupertinoTheme.of(context).textTheme.textStyle,
|
||||
child: ListView(
|
||||
children: [
|
||||
const SizedBox(height: 32),
|
||||
_buildDatePicker(context),
|
||||
_buildTimePicker(context),
|
||||
_buildDateAndTimePicker(context),
|
||||
_buildCountdownTimerPicker(context),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _BottomPicker extends StatelessWidget {
|
||||
const _BottomPicker({
|
||||
Key key,
|
||||
@required this.child,
|
||||
}) : assert(child != null),
|
||||
super(key: key);
|
||||
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
height: 216,
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
color: CupertinoColors.systemBackground.resolveFrom(context),
|
||||
child: DefaultTextStyle(
|
||||
style: TextStyle(
|
||||
color: CupertinoColors.label.resolveFrom(context),
|
||||
fontSize: 22,
|
||||
),
|
||||
child: GestureDetector(
|
||||
// Blocks taps from propagating to the modal sheet and popping.
|
||||
onTap: () {},
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Menu extends StatelessWidget {
|
||||
const _Menu({
|
||||
Key key,
|
||||
@required this.children,
|
||||
}) : assert(children != null),
|
||||
super(key: key);
|
||||
|
||||
final List<Widget> children;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
border: const Border(
|
||||
top: BorderSide(color: CupertinoColors.inactiveGray, width: 0),
|
||||
bottom: BorderSide(color: CupertinoColors.inactiveGray, width: 0),
|
||||
),
|
||||
),
|
||||
height: 44,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: children,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// END
|
||||
74
gallery/lib/demos/cupertino/cupertino_refresh_demo.dart
Normal file
74
gallery/lib/demos/cupertino/cupertino_refresh_demo.dart
Normal file
@@ -0,0 +1,74 @@
|
||||
// Copyright 2019 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:math' show Random;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gallery/l10n/gallery_localizations.dart';
|
||||
|
||||
// BEGIN cupertinoRefreshDemo
|
||||
|
||||
class CupertinoRefreshControlDemo extends StatefulWidget {
|
||||
@override
|
||||
_CupertinoRefreshControlDemoState createState() =>
|
||||
_CupertinoRefreshControlDemoState();
|
||||
}
|
||||
|
||||
class _CupertinoRefreshControlDemoState
|
||||
extends State<CupertinoRefreshControlDemo> {
|
||||
static const listCount = 20;
|
||||
var randomList = List<int>.generate(listCount, (i) => i + 1);
|
||||
|
||||
void _shuffleList() => randomList.shuffle(Random());
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
child: CustomScrollView(
|
||||
// If left unspecified, the [CustomScrollView] appends an
|
||||
// [AlwaysScrollableScrollPhysics]. Behind the scene, the ScrollableState
|
||||
// will attach that [AlwaysScrollableScrollPhysics] to the output of
|
||||
// [ScrollConfiguration.of] which will be a [ClampingScrollPhysics]
|
||||
// on Android.
|
||||
// To demonstrate the iOS behavior in this demo and to ensure that the list
|
||||
// always scrolls, we specifically use a [BouncingScrollPhysics] combined
|
||||
// with a [AlwaysScrollableScrollPhysics]
|
||||
physics: const BouncingScrollPhysics(
|
||||
parent: AlwaysScrollableScrollPhysics(),
|
||||
),
|
||||
slivers: [
|
||||
CupertinoSliverNavigationBar(
|
||||
automaticallyImplyLeading: false,
|
||||
largeTitle: Text(
|
||||
GalleryLocalizations.of(context).demoCupertinoPullToRefreshTitle,
|
||||
),
|
||||
),
|
||||
CupertinoSliverRefreshControl(
|
||||
onRefresh: () {
|
||||
return Future<void>.delayed(const Duration(seconds: 1))
|
||||
..then<void>((_) {
|
||||
if (mounted) {
|
||||
setState(() => _shuffleList());
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
final title = GalleryLocalizations.of(context)
|
||||
.starterAppDrawerItem(randomList[index]);
|
||||
return ListTile(title: Text(title));
|
||||
},
|
||||
childCount: listCount,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// END
|
||||
@@ -0,0 +1,87 @@
|
||||
// Copyright 2019 The Flutter team. 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:flutter/material.dart';
|
||||
|
||||
import 'package:gallery/l10n/gallery_localizations.dart';
|
||||
|
||||
// BEGIN cupertinoSegmentedControlDemo
|
||||
|
||||
class CupertinoSegmentedControlDemo extends StatefulWidget {
|
||||
@override
|
||||
_CupertinoSegmentedControlDemoState createState() =>
|
||||
_CupertinoSegmentedControlDemoState();
|
||||
}
|
||||
|
||||
class _CupertinoSegmentedControlDemoState
|
||||
extends State<CupertinoSegmentedControlDemo> {
|
||||
int currentSegment = 0;
|
||||
|
||||
void onValueChanged(int newValue) {
|
||||
setState(() {
|
||||
currentSegment = newValue;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final localizations = GalleryLocalizations.of(context);
|
||||
final segmentedControlMaxWidth = 500.0;
|
||||
final children = <int, Widget>{
|
||||
0: Text(localizations.colorsIndigo),
|
||||
1: Text(localizations.colorsTeal),
|
||||
2: Text(localizations.colorsCyan),
|
||||
};
|
||||
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
automaticallyImplyLeading: false,
|
||||
middle: Text(
|
||||
localizations.demoCupertinoSegmentedControlTitle,
|
||||
),
|
||||
),
|
||||
child: DefaultTextStyle(
|
||||
style: CupertinoTheme.of(context)
|
||||
.textTheme
|
||||
.textStyle
|
||||
.copyWith(fontSize: 13),
|
||||
child: SafeArea(
|
||||
child: ListView(
|
||||
children: [
|
||||
const SizedBox(height: 16),
|
||||
SizedBox(
|
||||
width: segmentedControlMaxWidth,
|
||||
child: CupertinoSegmentedControl<int>(
|
||||
children: children,
|
||||
onValueChanged: onValueChanged,
|
||||
groupValue: currentSegment,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: segmentedControlMaxWidth,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: CupertinoSlidingSegmentedControl<int>(
|
||||
children: children,
|
||||
onValueChanged: onValueChanged,
|
||||
groupValue: currentSegment,
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
height: 300,
|
||||
alignment: Alignment.center,
|
||||
child: children[currentSegment],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// END
|
||||
94
gallery/lib/demos/cupertino/cupertino_slider_demo.dart
Normal file
94
gallery/lib/demos/cupertino/cupertino_slider_demo.dart
Normal file
@@ -0,0 +1,94 @@
|
||||
// Copyright 2019 The Flutter team. 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:gallery/l10n/gallery_localizations.dart';
|
||||
|
||||
// BEGIN cupertinoSliderDemo
|
||||
|
||||
class CupertinoSliderDemo extends StatefulWidget {
|
||||
@override
|
||||
_CupertinoSliderDemoState createState() => _CupertinoSliderDemoState();
|
||||
}
|
||||
|
||||
class _CupertinoSliderDemoState extends State<CupertinoSliderDemo> {
|
||||
double _value = 25.0;
|
||||
double _discreteValue = 20.0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
automaticallyImplyLeading: false,
|
||||
middle: Text(GalleryLocalizations.of(context).demoCupertinoSliderTitle),
|
||||
),
|
||||
child: DefaultTextStyle(
|
||||
style: CupertinoTheme.of(context).textTheme.textStyle,
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: CupertinoSlider(
|
||||
value: _value,
|
||||
min: 0.0,
|
||||
max: 100.0,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_value = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
MergeSemantics(
|
||||
child: Text(
|
||||
GalleryLocalizations.of(context)
|
||||
.demoCupertinoSliderContinuous(
|
||||
_value.toStringAsFixed(1),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: CupertinoSlider(
|
||||
value: _discreteValue,
|
||||
min: 0.0,
|
||||
max: 100.0,
|
||||
divisions: 5,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_discreteValue = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
MergeSemantics(
|
||||
child: Text(
|
||||
GalleryLocalizations.of(context)
|
||||
.demoCupertinoSliderDiscrete(
|
||||
_discreteValue.toStringAsFixed(1),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// END
|
||||
47
gallery/lib/demos/cupertino/cupertino_switch_demo.dart
Normal file
47
gallery/lib/demos/cupertino/cupertino_switch_demo.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright 2019 The Flutter team. 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:gallery/l10n/gallery_localizations.dart';
|
||||
|
||||
// BEGIN cupertinoSwitchDemo
|
||||
|
||||
class CupertinoSwitchDemo extends StatefulWidget {
|
||||
@override
|
||||
_CupertinoSwitchDemoState createState() => _CupertinoSwitchDemoState();
|
||||
}
|
||||
|
||||
class _CupertinoSwitchDemoState extends State<CupertinoSwitchDemo> {
|
||||
bool _switchValue = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
automaticallyImplyLeading: false,
|
||||
middle: Text(
|
||||
GalleryLocalizations.of(context).demoSelectionControlsSwitchTitle,
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: Semantics(
|
||||
container: true,
|
||||
label:
|
||||
GalleryLocalizations.of(context).demoSelectionControlsSwitchTitle,
|
||||
child: CupertinoSwitch(
|
||||
value: _switchValue,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_switchValue = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// END
|
||||
88
gallery/lib/demos/cupertino/cupertino_tab_bar_demo.dart
Normal file
88
gallery/lib/demos/cupertino/cupertino_tab_bar_demo.dart
Normal file
@@ -0,0 +1,88 @@
|
||||
// Copyright 2019 The Flutter team. 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:gallery/l10n/gallery_localizations.dart';
|
||||
|
||||
// BEGIN cupertinoNavigationDemo
|
||||
|
||||
class _TabInfo {
|
||||
const _TabInfo(this.title, this.icon);
|
||||
|
||||
final String title;
|
||||
final IconData icon;
|
||||
}
|
||||
|
||||
class CupertinoTabBarDemo extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final _tabInfo = [
|
||||
_TabInfo(
|
||||
GalleryLocalizations.of(context).cupertinoTabBarHomeTab,
|
||||
CupertinoIcons.home,
|
||||
),
|
||||
_TabInfo(
|
||||
GalleryLocalizations.of(context).cupertinoTabBarChatTab,
|
||||
CupertinoIcons.conversation_bubble,
|
||||
),
|
||||
_TabInfo(
|
||||
GalleryLocalizations.of(context).cupertinoTabBarProfileTab,
|
||||
CupertinoIcons.profile_circled,
|
||||
),
|
||||
];
|
||||
|
||||
return DefaultTextStyle(
|
||||
style: CupertinoTheme.of(context).textTheme.textStyle,
|
||||
child: CupertinoTabScaffold(
|
||||
tabBar: CupertinoTabBar(
|
||||
items: [
|
||||
for (final tabInfo in _tabInfo)
|
||||
BottomNavigationBarItem(
|
||||
title: Text(tabInfo.title),
|
||||
icon: Icon(tabInfo.icon),
|
||||
),
|
||||
],
|
||||
),
|
||||
tabBuilder: (context, index) {
|
||||
return CupertinoTabView(
|
||||
builder: (context) => _CupertinoDemoTab(
|
||||
title: _tabInfo[index].title,
|
||||
icon: _tabInfo[index].icon,
|
||||
),
|
||||
defaultTitle: _tabInfo[index].title,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CupertinoDemoTab extends StatelessWidget {
|
||||
const _CupertinoDemoTab({
|
||||
Key key,
|
||||
@required this.title,
|
||||
@required this.icon,
|
||||
}) : super(key: key);
|
||||
|
||||
final String title;
|
||||
final IconData icon;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(),
|
||||
backgroundColor: CupertinoColors.systemBackground,
|
||||
child: Center(
|
||||
child: Icon(
|
||||
icon,
|
||||
semanticLabel: title,
|
||||
size: 100,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// END
|
||||
66
gallery/lib/demos/cupertino/cupertino_text_field_demo.dart
Normal file
66
gallery/lib/demos/cupertino/cupertino_text_field_demo.dart
Normal file
@@ -0,0 +1,66 @@
|
||||
// Copyright 2019 The Flutter team. 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:gallery/l10n/gallery_localizations.dart';
|
||||
|
||||
// BEGIN cupertinoTextFieldDemo
|
||||
|
||||
class CupertinoTextFieldDemo extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final localizations = GalleryLocalizations.of(context);
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
automaticallyImplyLeading: false,
|
||||
middle: Text(localizations.demoCupertinoTextFieldTitle),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: CupertinoTextField(
|
||||
placeholder: localizations.demoTextFieldEmail,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
clearButtonMode: OverlayVisibilityMode.editing,
|
||||
autocorrect: false,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: CupertinoTextField(
|
||||
placeholder: localizations.rallyLoginPassword,
|
||||
clearButtonMode: OverlayVisibilityMode.editing,
|
||||
obscureText: true,
|
||||
autocorrect: false,
|
||||
),
|
||||
),
|
||||
CupertinoTextField(
|
||||
prefix: Icon(
|
||||
CupertinoIcons.padlock_solid,
|
||||
size: 28,
|
||||
),
|
||||
padding: EdgeInsets.symmetric(horizontal: 6, vertical: 12),
|
||||
clearButtonMode: OverlayVisibilityMode.editing,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
width: 0,
|
||||
color: CupertinoColors.inactiveGray,
|
||||
),
|
||||
),
|
||||
),
|
||||
placeholder: localizations.demoCupertinoTextFieldPIN,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// END
|
||||
Reference in New Issue
Block a user