On the fly image conversion
This commit is contained in:
@@ -3,6 +3,10 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
||||
|
||||
import 'package:imagini/blocs/home_bloc.dart';
|
||||
import 'package:imagini/core/app_provider.dart';
|
||||
import 'package:imagini/graphql/imagini_graphql.dart';
|
||||
|
||||
class HomeScreen extends StatefulWidget {
|
||||
static const String PATH = '/Home';
|
||||
|
||||
@@ -14,19 +18,7 @@ class HomeScreen extends StatefulWidget {
|
||||
|
||||
class _HomeScreenState extends State<HomeScreen> {
|
||||
|
||||
// HomeBloc bloc;
|
||||
|
||||
void _init(){
|
||||
// if(null == bloc){
|
||||
// bloc = HomeBloc(AppProvider.getApplication(context));
|
||||
// }
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
// bloc.dispose();
|
||||
}
|
||||
HomeBloc bloc;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -38,6 +30,21 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
void _init(){
|
||||
if(bloc != null)
|
||||
return;
|
||||
|
||||
bloc = HomeBloc(AppProvider.getApplication(context));
|
||||
// bloc.mediaItemsResult.listen((bool status) {
|
||||
// });
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
// bloc.dispose();
|
||||
}
|
||||
|
||||
Widget _buildNavBar() {
|
||||
return PlatformNavBar(
|
||||
currentIndex: 0,
|
||||
@@ -76,29 +83,80 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
// );
|
||||
|
||||
|
||||
return new StaggeredGridView.countBuilder(
|
||||
crossAxisCount: 4,
|
||||
itemCount: 80,
|
||||
itemBuilder: (BuildContext context, int index) => _buildCard("https://i.imgur.com/CgSGqUz.jpeg"),
|
||||
// itemBuilder: (BuildContext context, int index) => new Container(
|
||||
// color: Colors.green,
|
||||
// child: new Center(
|
||||
// child: new CircleAvatar(
|
||||
// backgroundColor: Colors.white,
|
||||
// child: new Text('$index'),
|
||||
// ),
|
||||
// )),
|
||||
staggeredTileBuilder: (int index) =>
|
||||
// new StaggeredTile.count(2, index.isEven ? 2 : 1),
|
||||
new StaggeredTile.fit(2),
|
||||
mainAxisSpacing: 4.0,
|
||||
crossAxisSpacing: 4.0,
|
||||
// return new StaggeredGridView.countBuilder(
|
||||
// crossAxisCount: 4,
|
||||
// itemCount: 80,
|
||||
// itemBuilder: (BuildContext context, int index) => _buildCard("https://i.imgur.com/CgSGqUz.jpeg"),
|
||||
// // itemBuilder: (BuildContext context, int index) => new Container(
|
||||
// // color: Colors.green,
|
||||
// // child: new Center(
|
||||
// // child: new CircleAvatar(
|
||||
// // backgroundColor: Colors.white,
|
||||
// // child: new Text('$index'),
|
||||
// // ),
|
||||
// // )),
|
||||
// staggeredTileBuilder: (int index) =>
|
||||
// // new StaggeredTile.count(2, index.isEven ? 2 : 1),
|
||||
// new StaggeredTile.fit(2),
|
||||
// mainAxisSpacing: 4.0,
|
||||
// crossAxisSpacing: 4.0,
|
||||
// );
|
||||
|
||||
return StreamBuilder<MediaItems$Query>(
|
||||
stream: bloc.mediaItemsResult,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.data == null)
|
||||
return _appLoading();
|
||||
|
||||
List<MediaItems$Query$MediaItemResponse$MediaItem> allItems = snapshot.data.mediaItems.data;
|
||||
|
||||
return new StaggeredGridView.countBuilder(
|
||||
crossAxisCount: 4,
|
||||
itemCount: allItems.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
String fileName = allItems[index].fileName;
|
||||
print(fileName);
|
||||
return _buildCard("https://i.imgur.com/CgSGqUz.jpeg");
|
||||
},
|
||||
staggeredTileBuilder: (int index) =>
|
||||
// new StaggeredTile.count(2, index.isEven ? 2 : 1),
|
||||
new StaggeredTile.fit(2),
|
||||
mainAxisSpacing: 4.0,
|
||||
crossAxisSpacing: 4.0,
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Widget _appLoading(){
|
||||
return Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: 500),
|
||||
child: Container(
|
||||
margin: EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||
height: 270,
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
child: FittedBox(
|
||||
fit: BoxFit.contain,
|
||||
child: const FlutterLogo(),
|
||||
),
|
||||
width: 175,
|
||||
margin: EdgeInsets.fromLTRB(0, 0, 0, 50),
|
||||
),
|
||||
PlatformCircularProgressIndicator()
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCard(charImageUrl) {
|
||||
return new Image.network(
|
||||
charImageUrl,
|
||||
headers: {},
|
||||
fit: BoxFit.contain,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -19,12 +19,6 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
|
||||
LoginBloc bloc;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
// bloc.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_init();
|
||||
@@ -42,9 +36,8 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
}
|
||||
|
||||
void _init(){
|
||||
if(bloc != null){
|
||||
if(bloc != null)
|
||||
return;
|
||||
}
|
||||
|
||||
bloc = LoginBloc(AppProvider.getApplication(context));
|
||||
bloc.authenticatedResult.listen((bool status) {
|
||||
@@ -60,6 +53,12 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
// bloc.dispose();
|
||||
}
|
||||
|
||||
Widget _appLoading(){
|
||||
return Center(
|
||||
child: ConstrainedBox(
|
||||
|
||||
Reference in New Issue
Block a user