mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
81 lines
2.0 KiB
Dart
81 lines
2.0 KiB
Dart
// Copyright 2014 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.
|
|
|
|
// Flutter code sample for [CupertinoSearchTextField].
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
void main() => runApp(const SearchTextFieldApp());
|
|
|
|
class SearchTextFieldApp extends StatelessWidget {
|
|
const SearchTextFieldApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return const CupertinoApp(
|
|
theme: CupertinoThemeData(brightness: Brightness.light),
|
|
home: SearchTextFieldExample(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class SearchTextFieldExample extends StatefulWidget {
|
|
const SearchTextFieldExample({super.key});
|
|
|
|
@override
|
|
State<SearchTextFieldExample> createState() => _SearchTextFieldExampleState();
|
|
}
|
|
|
|
class _SearchTextFieldExampleState extends State<SearchTextFieldExample> {
|
|
String text = '';
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return CupertinoPageScaffold(
|
|
navigationBar: const CupertinoNavigationBar(
|
|
middle: Text('CupertinoSearchTextField Sample'),
|
|
),
|
|
child: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
Text(text),
|
|
Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: SearchTextField(
|
|
fieldValue: (String value) {
|
|
setState(() {
|
|
text = value;
|
|
});
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class SearchTextField extends StatelessWidget {
|
|
const SearchTextField({
|
|
super.key,
|
|
required this.fieldValue,
|
|
});
|
|
|
|
final ValueChanged<String> fieldValue;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return CupertinoSearchTextField(
|
|
onChanged: (String value) {
|
|
fieldValue('The text has changed to: $value');
|
|
},
|
|
onSubmitted: (String value) {
|
|
fieldValue('Submitted text: $value');
|
|
},
|
|
);
|
|
}
|
|
}
|