Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Added missing cupertino search text field demo. #708

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
535 changes: 535 additions & 0 deletions lib/codeviewer/code_segments.dart

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions lib/data/demos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,26 @@ List<GalleryDemo> cupertinoDemos(GalleryLocalizations localizations) {
],
category: GalleryDemoCategory.cupertino,
),
GalleryDemo(
title: localizations.demoCupertinoSearchTextFieldTitle,
icon: GalleryIcons.search,
slug: 'cupertino-search-text-field',
subtitle: localizations.demoCupertinoSearchTextFieldSubtitle,
configurations: [
GalleryDemoConfiguration(
title: localizations.demoCupertinoSearchTextFieldTitle,
description: localizations.demoCupertinoSearchTextFieldDescription,
documentationUrl:
'$_docsBaseUrl/cupertino/CupertinoSearchTextField-class.html',
buildRoute: (_) => DeferredWidget(
cupertinoLoader,
// ignore: prefer_const_constructors
() => cupertino_demos.CupertinoSearchTextFieldDemo()),
code: CodeSegments.cupertinoTextFieldDemo,
),
],
category: GalleryDemoCategory.cupertino,
),
];
}

Expand Down
1 change: 1 addition & 0 deletions lib/data/icons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,5 @@ class GalleryIcons {
static const IconData navigationRail = Icons.vertical_split;
static const IconData appbar = Icons.web_asset;
static const IconData divider = Icons.credit_card;
static const IconData search = Icons.search;
}
1 change: 1 addition & 0 deletions lib/demos/cupertino/cupertino_demos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export 'package:gallery/demos/cupertino/cupertino_button_demo.dart';
export 'package:gallery/demos/cupertino/cupertino_context_menu_demo.dart';
export 'package:gallery/demos/cupertino/cupertino_navigation_bar_demo.dart';
export 'package:gallery/demos/cupertino/cupertino_picker_demo.dart';
export 'package:gallery/demos/cupertino/cupertino_search_text_field_demo.dart';
export 'package:gallery/demos/cupertino/cupertino_segmented_control_demo.dart';
export 'package:gallery/demos/cupertino/cupertino_slider_demo.dart';
export 'package:gallery/demos/cupertino/cupertino_switch_demo.dart';
Expand Down
107 changes: 107 additions & 0 deletions lib/demos/cupertino/cupertino_search_text_field_demo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// 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:flutter_gen/gen_l10n/gallery_localizations.dart';

// BEGIN cupertinoSearchTextFieldDemo

class CupertinoSearchTextFieldDemo extends StatefulWidget {
const CupertinoSearchTextFieldDemo({super.key});

@override
State<CupertinoSearchTextFieldDemo> createState() =>
_CupertinoSearchTextFieldDemoState();
}

class _CupertinoSearchTextFieldDemoState
extends State<CupertinoSearchTextFieldDemo> {
final List<String> platforms = [
'Android',
'iOS',
'Windows',
'Linux',
'MacOS',
'Web'
];

final TextEditingController _queryTextController = TextEditingController();
String _searchPlatform = '';
List<String> filteredPlatforms = [];

@override
void initState() {
super.initState();
filteredPlatforms = platforms;
_queryTextController.addListener(() {
if (_queryTextController.text.isEmpty) {
setState(() {
_searchPlatform = '';
filteredPlatforms = platforms;
});
} else {
setState(() {
_searchPlatform = _queryTextController.text;
});
}
});
}

@override
Widget build(BuildContext context) {
final localizations = GalleryLocalizations.of(context)!;
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
automaticallyImplyLeading: false,
middle: Text(localizations.demoCupertinoSearchTextFieldTitle),
),
child: SafeArea(
child: Column(
children: [
CupertinoSearchTextField(
controller: _queryTextController,
restorationId: 'search_text_field',
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 12),
decoration: const BoxDecoration(
border: Border(
bottom: BorderSide(
width: 0,
color: CupertinoColors.inactiveGray,
),
),
),
placeholder:
localizations.demoCupertinoSearchTextFieldPlaceholder,
),
_buildPlatformList(),
],
),
),
);
}

Widget _buildPlatformList() {
if (_searchPlatform.isNotEmpty) {
List<String> tempList = [];
for (int i = 0; i < filteredPlatforms.length; i++) {
if (filteredPlatforms[i]
.toLowerCase()
.contains(_searchPlatform.toLowerCase())) {
tempList.add(filteredPlatforms[i]);
}
}
filteredPlatforms = tempList;
}
return ListView.builder(
itemCount: filteredPlatforms.length,
shrinkWrap: true,
itemBuilder: (context, index) {
return ListTile(title: Text(filteredPlatforms[index]));
},
);
}
}

// END
16 changes: 16 additions & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,22 @@
"@demoCupertinoTextFieldPIN": {
"description": "The placeholder for a text field where a user would enter their PIN number."
},
"demoCupertinoSearchTextFieldTitle": "Search text field",
"@demoCupertinoSearchTextFieldTitle": {
"description": "Title for the cupertino search text field demo."
},
"demoCupertinoSearchTextFieldSubtitle": "iOS-style search text field",
"@demoCupertinoSearchTextFieldSubtitle": {
"description": "Subtitle for the cupertino search text field demo."
},
"demoCupertinoSearchTextFieldDescription": "A search text field that lets the user search by entering text, and that can offer and filter suggestions.",
"@demoCupertinoSearchTextFieldDescription": {
"description": "Description for the cupertino search text field demo."
},
"demoCupertinoSearchTextFieldPlaceholder": "Enter some text",
"@demoCupertinoSearchTextFieldPlaceholder": {
"description": "The placeholder for a search text field demo."
},
"demoMotionTitle": "Motion",
"@demoMotionTitle": {
"description": "Title for the motion demo."
Expand Down
16 changes: 16 additions & 0 deletions lib/l10n/intl_en_US.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,22 @@
name="demoCupertinoTextFieldPIN"
description="The placeholder for a text field where a user would enter their PIN number."
>PIN</string>
<string
name="demoCupertinoSearchTextFieldTitle"
description="Title for the cupertino search text field demo."
>Search text field</string>
<string
name="demoCupertinoSearchTextFieldSubtitle"
description="Subtitle for the cupertino search text field demo."
>iOS-style search text field</string>
<string
name="demoCupertinoSearchTextFieldDescription"
description="Description for the cupertino search text field demo."
>A search text field that lets the user search by entering text, and that can offer and filter suggestions.</string>
<string
name="demoCupertinoSearchTextFieldPlaceholder"
description="The placeholder for a search text field demo."
>Enter some text</string>
<string
name="demoMotionTitle"
description="Title for the motion demo."
Expand Down