| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_easyloading/flutter_easyloading.dart';
- import 'package:flutter_styled_toast/flutter_styled_toast.dart';
- import 'package:prime_chat/screens/ProfileScreen.dart';
- import 'package:prime_chat/screens/components/Avatar.dart';
- import 'package:prime_chat/screens/components/ItemBuilder.dart';
- import '../basic/Method.dart';
- import 'components/ProgressDialog.dart';
- class SearchScreen extends StatefulWidget {
- const SearchScreen({Key? key}) : super(key: key);
- @override
- State<SearchScreen> createState() => _SearchScreenState();
- }
- class _SearchScreenState extends State<SearchScreen> {
- bool loading = false;
- List<Widget> children = [];
- @override
- Widget build(BuildContext context) {
- return ProgressDialog(
- loading: loading,
- label: "搜索中...",
- child: Scaffold(
- body: Column(
- children: [
- SearchBar(
- onSubmitted: (value) => _search(value),
- ),
- ...children
- ],
- ),
- ));
- }
- _search(String name) async {
- setState(() {
- loading = true;
- });
- final profile = await method.getProfile(name: name);
- debugPrint("get profile = ${profile?.name}");
- setState(() {
- loading = false;
- if (profile != null) {
- children.add(ListTile(
- leading: Avatar(profile.avatar),
- title: Text(profile.name),
- onTap: () {
- Navigator.push(
- context,
- MaterialPageRoute(
- builder: (context) =>
- ProfileScreen(profile: profile, isFriend: false)));
- },
- ));
- }
- });
- }
- }
- class SearchBar extends StatelessWidget {
- const SearchBar({Key? key, this.onSubmitted, this.onChanged})
- : super(key: key);
- final void Function(String)? onSubmitted;
- final void Function(String)? onChanged;
- @override
- Widget build(BuildContext context) {
- final theme = Theme.of(context);
- return Container(
- height: 80,
- color: theme.appBarTheme.backgroundColor,
- child: Column(
- children: [
- const SizedBox(
- height: 30,
- ),
- SizedBox(
- height: 40,
- child: Row(
- children: [
- Expanded(
- child: Container(
- // color: Colors.red,
- // width: MediaQuery.of(context).size.width - 50,
- margin: const EdgeInsets.symmetric(horizontal: 10),
- padding: const EdgeInsets.symmetric(horizontal: 10),
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.circular(6.0),
- ),
- child: TextField(
- cursorColor: Colors.green,
- autofocus: true,
- style: const TextStyle(
- fontSize: 18.0,
- color: Colors.black,
- fontWeight: FontWeight.w300,
- ),
- decoration: const InputDecoration(
- contentPadding: EdgeInsets.only(bottom: 10),
- icon: Icon(
- Icons.search,
- size: 20.0,
- color: Colors.grey,
- ),
- border: InputBorder.none,
- hintText: '搜索',
- hintStyle: TextStyle(color: Colors.grey),
- ),
- onSubmitted: onSubmitted,
- onChanged: onChanged,
- ),
- )),
- SizedBox(
- width: 40,
- // height: 34,
- child: GestureDetector(
- child: const Text("取消"),
- onTap: () => Navigator.pop(context),
- ))
- ],
- ),
- ),
- ],
- ),
- );
- }
- }
|