This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Widget _buildBar(BuildContext context) { | |
... | |
icon: _searchIcon, | |
onPressed: _searchPressed | |
... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_HomePageState() { | |
_filter.addListener(() { | |
if (_filter.text.isEmpty) { | |
setState(() { | |
_searchText = ""; | |
_resetRecords(); | |
}); | |
} else { | |
setState(() { | |
_searchText = _filter.text; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Widget _buildBar(BuildContext context) { | |
return new AppBar( | |
elevation: 0.1, | |
backgroundColor: appDarkGreyColor, | |
centerTitle: true, | |
title: _appBarTitle, | |
leading: new IconButton( | |
icon: _searchIcon | |
) | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: _buildBar(context), | |
backgroundColor: appDarkGreyColor, | |
body: _buildList(context), | |
resizeToAvoidBottomPadding: false, | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@override | |
void initState() { | |
super.initState(); | |
_records.records = new List(); | |
_filteredRecords.records = new List(); | |
_getRecords(); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
} |