Files
fcs/lib/pages/search_page.dart
2020-09-04 15:30:10 +06:30

114 lines
3.3 KiB
Dart

// Copyright 2019 The Chromium Authors. 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';
import 'package:provider/provider.dart';
import 'package:fcs/model/buyer_model.dart';
import 'package:fcs/fcs/common/helpers/theme.dart';
import 'package:fcs/vo/buyer.dart';
import 'buyer_list_row.dart';
Future<Buyer> showPlacesSearch(BuildContext context) async =>
await showSearch<Buyer>(
context: context,
delegate: UserSearchDelegate(),
);
class UserSearchDelegate extends SearchDelegate<Buyer> {
@override
ThemeData appBarTheme(BuildContext context) {
final ThemeData theme = Theme.of(context);
return theme.copyWith(
inputDecorationTheme: InputDecorationTheme(
hintStyle: TextStyle(
color: theme.primaryTextTheme.title.color, fontSize: 16)),
primaryColor: primaryColor,
primaryIconTheme: theme.primaryIconTheme.copyWith(color: Colors.white),
primaryColorBrightness: Brightness.light,
primaryTextTheme: theme.textTheme,
textTheme: theme.textTheme.copyWith(
title: theme.textTheme.title.copyWith(
color: theme.primaryTextTheme.title.color, fontSize: 16)),
);
}
@override
List<Widget> buildActions(BuildContext context) {
return [
IconButton(
icon: Icon(Icons.clear),
onPressed: () => query = '',
),
];
}
@override
Widget buildLeading(BuildContext context) {
return IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () => close(context, null),
);
}
@override
Widget buildResults(BuildContext context) {
final buyerModel = Provider.of<BuyerModel>(context);
return FutureBuilder(
future: buyerModel.search(query),
builder: (context, AsyncSnapshot<List<Buyer>> snapshot) {
if (snapshot.hasData) {
if (snapshot.data.length == 0) {
return Container(
child: Center(
child: Text(
"Error :No Search Buyer",
textAlign: TextAlign.center,
),
),
);
}
return Container(
padding: EdgeInsets.only(top: 15),
child: ListView(
children:
snapshot.data.map((u) => BuyerListRow(buyer: u)).toList(),
),
);
} else if (snapshot.hasError) {
return Container(
child: Center(
child: Text(
'${snapshot.error}',
textAlign: TextAlign.center,
),
),
);
} else {
return Container(
child: Center(
child: CircularProgressIndicator(
valueColor:
new AlwaysStoppedAnimation<Color>(primaryColor)),
),
);
}
});
}
@override
Widget buildSuggestions(BuildContext context) {
return Container(
child: Center(
child: Opacity(
opacity: 0.2,
child: Icon(
Icons.supervised_user_circle,
size: 200,
)),
),
);
}
}