Skip to content

Instantly share code, notes, and snippets.

View lawreyios's full-sized avatar
🎯
Focusing

Lawrence Tan lawreyios

🎯
Focusing
View GitHub Profile
Widget _buildBar(BuildContext context) {
...
icon: _searchIcon,
onPressed: _searchPressed
...
}
void _searchPressed() {
setState(() {
if (this._searchIcon.icon == Icons.search) {
this._searchIcon = new Icon(Icons.close);
this._appBarTitle = new TextField(
controller: _filter,
style: new TextStyle(color: Colors.white),
decoration: new InputDecoration(
prefixIcon: new Icon(Icons.search, color: Colors.white),
fillColor: Colors.white,
_HomePageState() {
_filter.addListener(() {
if (_filter.text.isEmpty) {
setState(() {
_searchText = "";
_resetRecords();
});
} else {
setState(() {
_searchText = _filter.text;
Widget _buildListItem(BuildContext context, Record record) {
return Card(
key: ValueKey(record.name),
elevation: 8.0,
margin: new EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
child: Container(
decoration: BoxDecoration(color: Color.fromRGBO(64, 75, 96, .9)),
child: ListTile(
contentPadding:
EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
Widget _buildList(BuildContext context) {
if (!(_searchText.isEmpty)) {
_filteredRecords.records = new List();
for (int i = 0; i < _records.records.length; i++) {
if (_records.records[i].name.toLowerCase().contains(_searchText.toLowerCase())
|| _records.records[i].address.toLowerCase().contains(_searchText.toLowerCase())) {
_filteredRecords.records.add(_records.records[i]);
}
}
}
Widget _buildBar(BuildContext context) {
return new AppBar(
elevation: 0.1,
backgroundColor: appDarkGreyColor,
centerTitle: true,
title: _appBarTitle,
leading: new IconButton(
icon: _searchIcon
)
);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: _buildBar(context),
backgroundColor: appDarkGreyColor,
body: _buildList(context),
resizeToAvoidBottomPadding: false,
);
}
@override
void initState() {
super.initState();
_records.records = new List();
_filteredRecords.records = new List();
_getRecords();
}
final TextEditingController _filter = new TextEditingController();
RecordList _records = new RecordList();
RecordList _filteredRecords = new RecordList();
String _searchText = "";
Icon _searchIcon = new Icon(Icons.search);
Widget _appBarTitle = new Text(appTitle);
import 'RecordList.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'dart:convert';
class RecordService {
Future<String> _loadRecordsAsset() async {
return await rootBundle.loadString('assets/data/records.json');
}