Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
4 contributors

Users who have contributed to this file

@filiph @efortuna @RedBrogdon @mjohnsullivan
131 lines (117 sloc) 3.59 KB
import 'dart:collection';
import 'package:flutter/material.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/foundation.dart';
import 'package:hn_app/src/article.dart';
import 'package:hn_app/src/hn_bloc.dart';
import 'package:webview_flutter/webview_flutter.dart';
void main() {
final hnBloc = HackerNewsBloc();
runApp(MyApp(bloc: hnBloc));
}
class MyApp extends StatelessWidget {
final HackerNewsBloc bloc;
MyApp({
Key key,
this.bloc,
}) : super(key: key);
static const primaryColor = Colors.white;
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: MyHomePage(
title: 'Flutter Hacker News',
bloc: bloc,
),
);
}
}
class MyHomePage extends StatefulWidget {
final HackerNewsBloc bloc;
final String title;
MyHomePage({Key key, this.title, this.bloc}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _currentIndex = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(widget.title)),
body: StreamBuilder<UnmodifiableListView<Article>>(
stream: widget.bloc.articles,
initialData: UnmodifiableListView<Article>([]),
builder: (context, snapshot) => ListView(
children: snapshot.data.map(_buildItem).toList(),
),
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
items: [
BottomNavigationBarItem(
title: Text('Top Stories'),
icon: Icon(Icons.arrow_drop_up),
),
BottomNavigationBarItem(
title: Text('New Stories'),
icon: Icon(Icons.new_releases),
),
],
onTap: (index) {
if (index == 0) {
widget.bloc.storiesType.add(StoriesType.topStories);
} else {
widget.bloc.storiesType.add(StoriesType.newStories);
}
setState(() {
_currentIndex = index;
});
},
),
);
}
Widget _buildItem(Article article) {
return ExpansionTile(
key: Key(article.title),
title: Text(article.title ?? '[null]'),
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Text('${article.descendants} comments'),
IconButton(
icon: Icon(Icons.launch),
onPressed: () async {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Scaffold(
appBar: AppBar(title: Text(article.title)),
body: WebView(
initialUrl: article.url,
javaScriptMode: JavaScriptMode.unrestricted,
))));
},
)
],
),
Container(
child: WebView(
initialUrl: article.url,
gestureRecognizers: Set()
..add(Factory<VerticalDragGestureRecognizer>(
() => VerticalDragGestureRecognizer())),
),
height: 200),
],
),
),
],
);
}
}
You can’t perform that action at this time.