Skip to content

Instantly share code, notes, and snippets.

@PeterHdd
Created September 28, 2023 13:16
Show Gist options
  • Save PeterHdd/db194e271fdfb334354bb3383ce6ed23 to your computer and use it in GitHub Desktop.
Save PeterHdd/db194e271fdfb334354bb3383ce6ed23 to your computer and use it in GitHub Desktop.
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. 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/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
final String title;
const MyHomePage({
Key? key,
required this.title,
}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SearchTextField(
hintText: 'Title',
onSubmitted: (searchText) {
print("submitted $searchText");
},
onChanged: (changedText) {
print("changed $changedText");
},
),
],
),
),
);
}
}
class SearchTextField extends StatelessWidget {
final String hintText;
final Function(String value) onSubmitted;
final Function(String value) onChanged;
const SearchTextField({
required this.hintText,
required this.onSubmitted,
required this.onChanged,
super.key,
});
@override
Widget build(BuildContext context) {
return Container(
height: 48,
width: double.infinity,
clipBehavior: Clip.antiAlias,
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: TextField(
onSubmitted: onSubmitted,
onChanged: onChanged,
textInputAction: TextInputAction.search,
decoration: InputDecoration(
filled: true,
contentPadding: const EdgeInsets.symmetric(
vertical: 14,
horizontal: 16,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide.none,
),
hintText: hintText,
hintStyle: const TextStyle(
color: Color(0xFFACACAC),
fontSize: 15,
fontFamily: 'SF Pro Text',
fontWeight: FontWeight.w400,
height: 1.33,
letterSpacing: -0.24,
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment