Skip to content

Instantly share code, notes, and snippets.

@arifsuhan
Last active May 4, 2019 14:17
Show Gist options
  • Save arifsuhan/9a0a3868fbb3d4f524ea1fce42ecf93d to your computer and use it in GitHub Desktop.
Save arifsuhan/9a0a3868fbb3d4f524ea1fce42ecf93d to your computer and use it in GitHub Desktop.
Bangla Book List & Rating
// Add a new route to hold the favorites.
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'বাংলা বই সমগ্র',
theme: new ThemeData(
primaryColor: Colors.black
),
home: new RandomWords(),
);
}
}
class RandomWords extends StatefulWidget {
@override
RandomWordsState createState() => new RandomWordsState();
}
class RandomWordsState extends State<RandomWords> {
final List <String> _suggestions = new List <String>();
final Set<String> _saved = new Set<String>();
final TextStyle _biggerFont = const TextStyle(fontSize: 14.0);
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: const Text('বাংলা বই সমগ্র'),
actions: <Widget>[
new IconButton(icon: const Icon(Icons.list), onPressed: _pushSaved),
],
),
body: _buildSuggestions(),
);
}
Widget _buildSuggestions() {
_suggestions.add("লোটাকম্বল ২য় খন্ড - সঞ্জীব চট্টোপাধ্যায় ");
_suggestions.add("একুশের গল্প- জহির রায়হান");
_suggestions.add("কতো নদী সরোবর - হুমায়ুন আজাদ ");
_suggestions.add("নারী - হুমায়ুন আজাদ ");
_suggestions.add("গর্ভধারিনী - সমরেশ মজুমদার");
_suggestions.add("আলোর পাখিরা - শাহরিয়ার কবির");
_suggestions.add("হানাবাড়ির রহস্য - শাহরিয়ার কবির ");
_suggestions.add("ফেলুদা সমগ্র ১ - সত্যজিৎ রায়");
return new ListView.builder(
padding: const EdgeInsets.all(15.0),
itemBuilder: (BuildContext _context, int i) {
int index = i;
return _buildRow(_suggestions[index]);
},
itemCount: 8,
);
}
Widget _buildRow(String pair) {
final bool alreadySaved = _saved.contains(pair);
return new ListTile(
title: new Text(
pair,
style: _biggerFont,
),
trailing: new Icon(
alreadySaved ? Icons.favorite : Icons.favorite_border,
color: alreadySaved ? Colors.red : null,
),
onTap: () {
setState(() {
if (alreadySaved) {
_saved.remove(pair);
} else {
_saved.add(pair);
}
});
},
);
}
void _pushSaved() {
Navigator.of(context).push(
new MaterialPageRoute<void>(
builder: (BuildContext context) {
final Iterable<ListTile> tiles = _saved.map(
(String pair) {
final bool alreadySaved = _saved.contains(pair);
return new ListTile(
title: new Text(
pair,
style: _biggerFont,
),
// trailing: new Icon(
// alreadySaved ? Icons.favorite : Icons.favorite_border,
// color: alreadySaved ? Colors.red : null,
// ),
);
},
);
final List<Widget> divided = ListTile
.divideTiles(
context: context,
tiles: tiles,
)
.toList();
return new Scaffold(
appBar: new AppBar(
title: const Text('পছন্দের বইয়ের তালিকা'),
),
body: new ListView(children: divided),
);
},
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment