[Gallery] Implement cupertino pull-to-refresh demo (#221)

* Implement cupertino pull-to-refresh demo

* Address feedback
pull/222/head
rami-a 5 years ago committed by GitHub
parent a55a53c31e
commit 3b61899119
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -842,6 +842,377 @@ class CodeSegments {
]); ]);
} }
static TextSpan cupertinoRefreshDemo(BuildContext context) {
final CodeStyle codeStyle = CodeStyle.of(context);
return TextSpan(children: [
TextSpan(
style: codeStyle.commentStyle,
text: '// Copyright 2019 The Flutter team. All rights reserved.'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a'),
TextSpan(
style: codeStyle.commentStyle,
text:
'// Use of this source code is governed by a BSD-style license that can be'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a'),
TextSpan(
style: codeStyle.commentStyle, text: '// found in the LICENSE file.'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a\u000a'),
TextSpan(style: codeStyle.keywordStyle, text: 'import'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.stringStyle, text: '\u0027dart:math\u0027'),
TextSpan(style: codeStyle.baseStyle, text: ' show '),
TextSpan(style: codeStyle.classStyle, text: 'Random'),
TextSpan(style: codeStyle.punctuationStyle, text: ';'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a\u000a'),
TextSpan(style: codeStyle.keywordStyle, text: 'import'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(
style: codeStyle.stringStyle,
text: '\u0027package:flutter/cupertino.dart\u0027'),
TextSpan(style: codeStyle.punctuationStyle, text: ';'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a'),
TextSpan(style: codeStyle.keywordStyle, text: 'import'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(
style: codeStyle.stringStyle,
text: '\u0027package:flutter/material.dart\u0027'),
TextSpan(style: codeStyle.punctuationStyle, text: ';'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a'),
TextSpan(style: codeStyle.keywordStyle, text: 'import'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(
style: codeStyle.stringStyle,
text: '\u0027package:gallery/l10n/gallery_localizations.dart\u0027'),
TextSpan(style: codeStyle.punctuationStyle, text: ';'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a\u000a'),
TextSpan(style: codeStyle.keywordStyle, text: 'class'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(
style: codeStyle.classStyle, text: 'CupertinoRefreshControlDemo'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.keywordStyle, text: 'extends'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.classStyle, text: 'StatefulWidget'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.punctuationStyle, text: '{'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.keywordStyle, text: '@override'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(
style: codeStyle.classStyle,
text: '_CupertinoRefreshControlDemoState'),
TextSpan(style: codeStyle.baseStyle, text: ' createState'),
TextSpan(style: codeStyle.punctuationStyle, text: '()'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.punctuationStyle, text: '=>'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(
style: codeStyle.classStyle,
text: '_CupertinoRefreshControlDemoState'),
TextSpan(style: codeStyle.punctuationStyle, text: '();'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a'),
TextSpan(style: codeStyle.punctuationStyle, text: '}'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a\u000a'),
TextSpan(style: codeStyle.keywordStyle, text: 'class'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(
style: codeStyle.classStyle,
text: '_CupertinoRefreshControlDemoState'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.keywordStyle, text: 'extends'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.classStyle, text: 'State'),
TextSpan(style: codeStyle.punctuationStyle, text: '<'),
TextSpan(
style: codeStyle.classStyle, text: 'CupertinoRefreshControlDemo'),
TextSpan(style: codeStyle.punctuationStyle, text: '>'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.punctuationStyle, text: '{'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.keywordStyle, text: 'static'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.keywordStyle, text: 'const'),
TextSpan(style: codeStyle.baseStyle, text: ' listCount '),
TextSpan(style: codeStyle.punctuationStyle, text: '='),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.numberStyle, text: '20'),
TextSpan(style: codeStyle.punctuationStyle, text: ';'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.keywordStyle, text: 'var'),
TextSpan(style: codeStyle.baseStyle, text: ' randomList '),
TextSpan(style: codeStyle.punctuationStyle, text: '='),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.classStyle, text: 'List'),
TextSpan(style: codeStyle.punctuationStyle, text: '<'),
TextSpan(style: codeStyle.keywordStyle, text: 'int'),
TextSpan(style: codeStyle.punctuationStyle, text: '>.'),
TextSpan(style: codeStyle.baseStyle, text: 'generate'),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(style: codeStyle.baseStyle, text: 'listCount'),
TextSpan(style: codeStyle.punctuationStyle, text: ','),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(style: codeStyle.baseStyle, text: 'i'),
TextSpan(style: codeStyle.punctuationStyle, text: ')'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.punctuationStyle, text: '=>'),
TextSpan(style: codeStyle.baseStyle, text: ' i '),
TextSpan(style: codeStyle.punctuationStyle, text: '+'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.numberStyle, text: '1'),
TextSpan(style: codeStyle.punctuationStyle, text: ');'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a\u000a '),
TextSpan(style: codeStyle.keywordStyle, text: 'void'),
TextSpan(style: codeStyle.baseStyle, text: ' _shuffleList'),
TextSpan(style: codeStyle.punctuationStyle, text: '()'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.punctuationStyle, text: '=>'),
TextSpan(style: codeStyle.baseStyle, text: ' randomList'),
TextSpan(style: codeStyle.punctuationStyle, text: '.'),
TextSpan(style: codeStyle.baseStyle, text: 'shuffle'),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(style: codeStyle.classStyle, text: 'Random'),
TextSpan(style: codeStyle.punctuationStyle, text: '());'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a\u000a '),
TextSpan(style: codeStyle.keywordStyle, text: '@override'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.classStyle, text: 'Widget'),
TextSpan(style: codeStyle.baseStyle, text: ' build'),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(style: codeStyle.classStyle, text: 'BuildContext'),
TextSpan(style: codeStyle.baseStyle, text: ' context'),
TextSpan(style: codeStyle.punctuationStyle, text: ')'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.punctuationStyle, text: '{'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.keywordStyle, text: 'return'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.classStyle, text: 'CupertinoPageScaffold'),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(style: codeStyle.baseStyle, text: '\u000a child'),
TextSpan(style: codeStyle.punctuationStyle, text: ':'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.classStyle, text: 'CustomScrollView'),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(
style: codeStyle.commentStyle,
text: '// If left unspecified, the [CustomScrollView] appends an'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(
style: codeStyle.commentStyle,
text:
'// [AlwaysScrollableScrollPhysics]. Behind the scene, the ScrollableState'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(
style: codeStyle.commentStyle,
text:
'// will attach that [AlwaysScrollableScrollPhysics] to the output of'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(
style: codeStyle.commentStyle,
text:
'// [ScrollConfiguration.of] which will be a [ClampingScrollPhysics]'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.commentStyle, text: '// on Android.'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(
style: codeStyle.commentStyle,
text:
'// To demonstrate the iOS behavior in this demo and to ensure that the list'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(
style: codeStyle.commentStyle,
text:
'// always scrolls, we specifically use a [BouncingScrollPhysics] combined'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(
style: codeStyle.commentStyle,
text: '// with a [AlwaysScrollableScrollPhysics]'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a physics'),
TextSpan(style: codeStyle.punctuationStyle, text: ':'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.keywordStyle, text: 'const'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.classStyle, text: 'BouncingScrollPhysics'),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(style: codeStyle.baseStyle, text: '\u000a parent'),
TextSpan(style: codeStyle.punctuationStyle, text: ':'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(
style: codeStyle.classStyle, text: 'AlwaysScrollableScrollPhysics'),
TextSpan(style: codeStyle.punctuationStyle, text: '(),'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: '),'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a slivers'),
TextSpan(style: codeStyle.punctuationStyle, text: ':'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.punctuationStyle, text: '['),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(
style: codeStyle.classStyle, text: 'CupertinoSliverNavigationBar'),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(
style: codeStyle.baseStyle,
text: '\u000a automaticallyImplyLeading'),
TextSpan(style: codeStyle.punctuationStyle, text: ':'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.keywordStyle, text: 'false'),
TextSpan(style: codeStyle.punctuationStyle, text: ','),
TextSpan(
style: codeStyle.baseStyle, text: '\u000a largeTitle'),
TextSpan(style: codeStyle.punctuationStyle, text: ':'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.classStyle, text: 'Text'),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.classStyle, text: 'GalleryLocalizations'),
TextSpan(style: codeStyle.punctuationStyle, text: '.'),
TextSpan(style: codeStyle.baseStyle, text: 'of'),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(style: codeStyle.baseStyle, text: 'context'),
TextSpan(style: codeStyle.punctuationStyle, text: ').'),
TextSpan(
style: codeStyle.baseStyle, text: 'demoCupertinoPullToRefreshTitle'),
TextSpan(style: codeStyle.punctuationStyle, text: ','),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: '),'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: '),'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(
style: codeStyle.classStyle, text: 'CupertinoSliverRefreshControl'),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(style: codeStyle.baseStyle, text: '\u000a onRefresh'),
TextSpan(style: codeStyle.punctuationStyle, text: ':'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.punctuationStyle, text: '()'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.punctuationStyle, text: '{'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.keywordStyle, text: 'return'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.classStyle, text: 'Future'),
TextSpan(style: codeStyle.punctuationStyle, text: '<'),
TextSpan(style: codeStyle.keywordStyle, text: 'void'),
TextSpan(style: codeStyle.punctuationStyle, text: '>.'),
TextSpan(style: codeStyle.baseStyle, text: 'delayed'),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(style: codeStyle.keywordStyle, text: 'const'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.classStyle, text: 'Duration'),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(style: codeStyle.baseStyle, text: 'seconds'),
TextSpan(style: codeStyle.punctuationStyle, text: ':'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.numberStyle, text: '1'),
TextSpan(style: codeStyle.punctuationStyle, text: '))'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: '..'),
TextSpan(style: codeStyle.baseStyle, text: 'then'),
TextSpan(style: codeStyle.punctuationStyle, text: '<'),
TextSpan(style: codeStyle.keywordStyle, text: 'void'),
TextSpan(style: codeStyle.punctuationStyle, text: '>(('),
TextSpan(style: codeStyle.baseStyle, text: '_'),
TextSpan(style: codeStyle.punctuationStyle, text: ')'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.punctuationStyle, text: '{'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.keywordStyle, text: 'if'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(style: codeStyle.baseStyle, text: 'mounted'),
TextSpan(style: codeStyle.punctuationStyle, text: ')'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.punctuationStyle, text: '{'),
TextSpan(
style: codeStyle.baseStyle,
text: '\u000a setState'),
TextSpan(style: codeStyle.punctuationStyle, text: '(()'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.punctuationStyle, text: '=>'),
TextSpan(style: codeStyle.baseStyle, text: ' _shuffleList'),
TextSpan(style: codeStyle.punctuationStyle, text: '());'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: '}'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: '});'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: '},'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: '),'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.classStyle, text: 'SliverList'),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(style: codeStyle.baseStyle, text: '\u000a delegate'),
TextSpan(style: codeStyle.punctuationStyle, text: ':'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.classStyle, text: 'SliverChildBuilderDelegate'),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(style: codeStyle.baseStyle, text: 'context'),
TextSpan(style: codeStyle.punctuationStyle, text: ','),
TextSpan(style: codeStyle.baseStyle, text: ' index'),
TextSpan(style: codeStyle.punctuationStyle, text: ')'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.punctuationStyle, text: '{'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.keywordStyle, text: 'final'),
TextSpan(style: codeStyle.baseStyle, text: ' title '),
TextSpan(style: codeStyle.punctuationStyle, text: '='),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.classStyle, text: 'GalleryLocalizations'),
TextSpan(style: codeStyle.punctuationStyle, text: '.'),
TextSpan(style: codeStyle.baseStyle, text: 'of'),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(style: codeStyle.baseStyle, text: 'context'),
TextSpan(style: codeStyle.punctuationStyle, text: ')'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: '.'),
TextSpan(style: codeStyle.baseStyle, text: 'starterAppDrawerItem'),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(style: codeStyle.baseStyle, text: 'randomList'),
TextSpan(style: codeStyle.punctuationStyle, text: '['),
TextSpan(style: codeStyle.baseStyle, text: 'index'),
TextSpan(style: codeStyle.punctuationStyle, text: ']);'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.keywordStyle, text: 'return'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.classStyle, text: 'ListTile'),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(style: codeStyle.baseStyle, text: 'title'),
TextSpan(style: codeStyle.punctuationStyle, text: ':'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.classStyle, text: 'Text'),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(style: codeStyle.baseStyle, text: 'title'),
TextSpan(style: codeStyle.punctuationStyle, text: '));'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: '},'),
TextSpan(
style: codeStyle.baseStyle, text: '\u000a childCount'),
TextSpan(style: codeStyle.punctuationStyle, text: ':'),
TextSpan(style: codeStyle.baseStyle, text: ' listCount'),
TextSpan(style: codeStyle.punctuationStyle, text: ','),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: '),'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: '),'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: '],'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: '),'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: ');'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: '}'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a'),
TextSpan(style: codeStyle.punctuationStyle, text: '}'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a\u000a'),
]);
}
static TextSpan cupertinoNavigationDemo(BuildContext context) { static TextSpan cupertinoNavigationDemo(BuildContext context) {
final CodeStyle codeStyle = CodeStyle.of(context); final CodeStyle codeStyle = CodeStyle.of(context);
return TextSpan(children: [ return TextSpan(children: [

@ -12,6 +12,7 @@ import 'package:gallery/demos/cupertino/cupertino_activity_indicator_demo.dart';
import 'package:gallery/demos/cupertino/cupertino_alert_demo.dart'; import 'package:gallery/demos/cupertino/cupertino_alert_demo.dart';
import 'package:gallery/demos/cupertino/cupertino_button_demo.dart'; import 'package:gallery/demos/cupertino/cupertino_button_demo.dart';
import 'package:gallery/demos/cupertino/cupertino_navigation_bar_demo.dart'; import 'package:gallery/demos/cupertino/cupertino_navigation_bar_demo.dart';
import 'package:gallery/demos/cupertino/cupertino_refresh_demo.dart';
import 'package:gallery/demos/cupertino/cupertino_segmented_control_demo.dart'; import 'package:gallery/demos/cupertino/cupertino_segmented_control_demo.dart';
import 'package:gallery/demos/cupertino/cupertino_slider_demo.dart'; import 'package:gallery/demos/cupertino/cupertino_slider_demo.dart';
import 'package:gallery/demos/cupertino/cupertino_switch_demo.dart'; import 'package:gallery/demos/cupertino/cupertino_switch_demo.dart';
@ -673,6 +674,24 @@ List<GalleryDemo> cupertinoDemos(BuildContext context) {
), ),
], ],
), ),
GalleryDemo(
title: GalleryLocalizations.of(context).demoCupertinoPullToRefreshTitle,
icon: GalleryIcons.cupertinoPullToRefresh,
subtitle:
GalleryLocalizations.of(context).demoCupertinoPullToRefreshSubtitle,
configurations: [
GalleryDemoConfiguration(
title:
GalleryLocalizations.of(context).demoCupertinoPullToRefreshTitle,
description: GalleryLocalizations.of(context)
.demoCupertinoPullToRefreshDescription,
documentationUrl:
'https://api.flutter.dev/flutter/cupertino/CupertinoSliverRefreshControl-class.html',
buildRoute: (_) => CupertinoRefreshControlDemo(),
code: CodeSegments.cupertinoRefreshDemo,
),
],
),
GalleryDemo( GalleryDemo(
title: title:
GalleryLocalizations.of(context).demoCupertinoSegmentedControlTitle, GalleryLocalizations.of(context).demoCupertinoSegmentedControlTitle,

@ -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

@ -1681,6 +1681,28 @@ class GalleryLocalizations {
desc: r'Title for the cupertino navigation bar component demo.'); desc: r'Title for the cupertino navigation bar component demo.');
} }
String get demoCupertinoPullToRefreshDescription {
return Intl.message(
r'A widget implementing the iOS-style pull to refresh content control.',
locale: _localeName,
name: 'demoCupertinoPullToRefreshDescription',
desc: r'Description for the cupertino pull-to-refresh component demo.');
}
String get demoCupertinoPullToRefreshSubtitle {
return Intl.message(r'iOS-style pull to refresh control',
locale: _localeName,
name: 'demoCupertinoPullToRefreshSubtitle',
desc: r'Subtitle for the cupertino pull-to-refresh component demo.');
}
String get demoCupertinoPullToRefreshTitle {
return Intl.message(r'Pull To Refresh',
locale: _localeName,
name: 'demoCupertinoPullToRefreshTitle',
desc: r'Title for the cupertino pull-to-refresh component demo.');
}
String get demoCupertinoSegmentedControlDescription { String get demoCupertinoSegmentedControlDescription {
return Intl.message( return Intl.message(
r'Used to select between a number of mutually exclusive options. When one option in the segmented control is selected, the other options in the segmented control cease to be selected.', r'Used to select between a number of mutually exclusive options. When one option in the segmented control is selected, the other options in the segmented control cease to be selected.',

@ -887,6 +887,18 @@
"@demoCupertinoNavigationBarDescription": { "@demoCupertinoNavigationBarDescription": {
"description": "Description for the cupertino navigation bar component demo." "description": "Description for the cupertino navigation bar component demo."
}, },
"demoCupertinoPullToRefreshTitle": "Pull To Refresh",
"@demoCupertinoPullToRefreshTitle": {
"description": "Title for the cupertino pull-to-refresh component demo."
},
"demoCupertinoPullToRefreshSubtitle": "iOS-style pull to refresh control",
"@demoCupertinoPullToRefreshSubtitle": {
"description": "Subtitle for the cupertino pull-to-refresh component demo."
},
"demoCupertinoPullToRefreshDescription": "A widget implementing the iOS-style pull to refresh content control.",
"@demoCupertinoPullToRefreshDescription": {
"description": "Description for the cupertino pull-to-refresh component demo."
},
"demoCupertinoSegmentedControlTitle": "Segmented Control", "demoCupertinoSegmentedControlTitle": "Segmented Control",
"@demoCupertinoSegmentedControlTitle": { "@demoCupertinoSegmentedControlTitle": {
"description": "Title for the cupertino segmented control component demo." "description": "Title for the cupertino segmented control component demo."

@ -841,6 +841,18 @@
name="demoCupertinoNavigationBarDescription" name="demoCupertinoNavigationBarDescription"
description="Description for the cupertino navigation bar component demo." description="Description for the cupertino navigation bar component demo."
>An iOS-styled navigation bar. The navigation bar is a toolbar that minimally consists of a page title, in the middle of the toolbar.</string> >An iOS-styled navigation bar. The navigation bar is a toolbar that minimally consists of a page title, in the middle of the toolbar.</string>
<string
name="demoCupertinoPullToRefreshTitle"
description="Title for the cupertino pull-to-refresh component demo."
>Pull To Refresh</string>
<string
name="demoCupertinoPullToRefreshSubtitle"
description="Subtitle for the cupertino pull-to-refresh component demo."
>iOS-style pull to refresh control</string>
<string
name="demoCupertinoPullToRefreshDescription"
description="Description for the cupertino pull-to-refresh component demo."
>A widget implementing the iOS-style pull to refresh content control.</string>
<string <string
name="demoCupertinoSegmentedControlTitle" name="demoCupertinoSegmentedControlTitle"
description="Title for the cupertino segmented control component demo." description="Title for the cupertino segmented control component demo."

@ -442,6 +442,14 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("iOS-style navigation bar"), MessageLookupByLibrary.simpleMessage("iOS-style navigation bar"),
"demoCupertinoNavigationBarTitle": "demoCupertinoNavigationBarTitle":
MessageLookupByLibrary.simpleMessage("Navigation Bar"), MessageLookupByLibrary.simpleMessage("Navigation Bar"),
"demoCupertinoPullToRefreshDescription":
MessageLookupByLibrary.simpleMessage(
"A widget implementing the iOS-style pull to refresh content control."),
"demoCupertinoPullToRefreshSubtitle":
MessageLookupByLibrary.simpleMessage(
"iOS-style pull to refresh control"),
"demoCupertinoPullToRefreshTitle":
MessageLookupByLibrary.simpleMessage("Pull To Refresh"),
"demoCupertinoSegmentedControlDescription": "demoCupertinoSegmentedControlDescription":
MessageLookupByLibrary.simpleMessage( MessageLookupByLibrary.simpleMessage(
"Used to select between a number of mutually exclusive options. When one option in the segmented control is selected, the other options in the segmented control cease to be selected."), "Used to select between a number of mutually exclusive options. When one option in the segmented control is selected, the other options in the segmented control cease to be selected."),

Loading…
Cancel
Save