2021-02-11 20:47:42 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2021-03-01 00:23:41 +00:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2021-02-11 20:47:42 +00:00
|
|
|
|
|
|
|
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
|
|
|
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
2021-02-22 03:36:25 +00:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
2021-04-06 00:40:23 +00:00
|
|
|
import 'package:photo_view/photo_view_gallery.dart';
|
|
|
|
import 'package:photo_view/photo_view.dart';
|
2021-02-11 20:47:42 +00:00
|
|
|
|
2021-02-21 17:31:03 +00:00
|
|
|
import 'package:imagini/blocs/home_bloc.dart';
|
|
|
|
import 'package:imagini/core/app_provider.dart';
|
|
|
|
|
2021-02-11 20:47:42 +00:00
|
|
|
class HomeScreen extends StatefulWidget {
|
|
|
|
static const String PATH = '/Home';
|
|
|
|
|
|
|
|
HomeScreen({Key key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_HomeScreenState createState() => _HomeScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _HomeScreenState extends State<HomeScreen> {
|
|
|
|
|
2021-02-21 17:31:03 +00:00
|
|
|
HomeBloc bloc;
|
2021-02-11 20:47:42 +00:00
|
|
|
|
2021-03-01 00:23:41 +00:00
|
|
|
int _currentIndex = 0;
|
|
|
|
int _totalLength = 1;
|
|
|
|
|
2021-02-11 20:47:42 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
_init();
|
|
|
|
|
|
|
|
return PlatformScaffold(
|
2021-03-01 00:23:41 +00:00
|
|
|
body: _buildBody(),
|
2021-02-11 20:47:42 +00:00
|
|
|
bottomNavBar: _buildNavBar()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-21 17:31:03 +00:00
|
|
|
void _init(){
|
|
|
|
if(bloc != null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bloc = HomeBloc(AppProvider.getApplication(context));
|
2021-03-01 00:23:41 +00:00
|
|
|
}
|
|
|
|
|
2021-02-21 17:31:03 +00:00
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
super.dispose();
|
|
|
|
// bloc.dispose();
|
|
|
|
}
|
|
|
|
|
2021-03-01 00:23:41 +00:00
|
|
|
Widget _buildBody() {
|
|
|
|
var widgetMap = [
|
|
|
|
<Widget>[
|
|
|
|
_buildAppBar("Gallery"),
|
2021-03-04 06:06:09 +00:00
|
|
|
_buildGridView()
|
2021-03-01 00:23:41 +00:00
|
|
|
],
|
|
|
|
<Widget>[
|
|
|
|
_buildAppBar("Albums"),
|
|
|
|
SliverToBoxAdapter()
|
|
|
|
],
|
|
|
|
<Widget>[
|
|
|
|
_buildAppBar("Settings"),
|
|
|
|
SliverToBoxAdapter()
|
|
|
|
],
|
|
|
|
];
|
|
|
|
return CustomScrollView(
|
|
|
|
shrinkWrap: true,
|
|
|
|
slivers: widgetMap[_currentIndex],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildAppBar(String title) {
|
|
|
|
return SliverAppBar(
|
|
|
|
title: new Text(title),
|
|
|
|
pinned: false,
|
|
|
|
snap: false,
|
|
|
|
floating: true,
|
|
|
|
leading: PlatformIconButton(
|
|
|
|
icon: Icon(PlatformIcons(context).person),
|
|
|
|
),
|
|
|
|
actions: <Widget>[
|
|
|
|
PlatformIconButton(
|
|
|
|
icon: Icon(PlatformIcons(context).search),
|
2021-02-11 20:47:42 +00:00
|
|
|
),
|
2021-03-01 00:23:41 +00:00
|
|
|
PlatformIconButton(
|
|
|
|
icon: Icon(PlatformIcons(context).add),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
2021-02-11 20:47:42 +00:00
|
|
|
}
|
|
|
|
|
2021-03-01 00:23:41 +00:00
|
|
|
Widget _buildNavBar() {
|
|
|
|
return PlatformNavBar(
|
|
|
|
currentIndex: _currentIndex,
|
|
|
|
itemChanged: (index) => setState(() {
|
|
|
|
_currentIndex = index;
|
|
|
|
}),
|
|
|
|
items: [
|
|
|
|
BottomNavigationBarItem(
|
|
|
|
label: "Photos",
|
|
|
|
icon: Icon(isMaterial(context) ? Icons.insert_photo : CupertinoIcons.photo),
|
|
|
|
),
|
|
|
|
BottomNavigationBarItem(
|
|
|
|
label: "Albums",
|
|
|
|
icon: Icon(isMaterial(context) ? Icons.collections : CupertinoIcons.photo_on_rectangle),
|
|
|
|
),
|
|
|
|
BottomNavigationBarItem(
|
|
|
|
label: "Settings",
|
|
|
|
icon: Icon(PlatformIcons(context).settings),
|
|
|
|
),
|
|
|
|
],
|
2021-02-21 17:31:03 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-06 00:40:23 +00:00
|
|
|
// Widget _buildPhotoPreview(){
|
|
|
|
// return Container(
|
|
|
|
// child: PhotoViewGallery.builder(
|
|
|
|
// scrollPhysics: const BouncingScrollPhysics(),
|
|
|
|
// builder: (BuildContext context, int index) {
|
|
|
|
// return PhotoViewGalleryPageOptions(
|
|
|
|
// imageProvider: AssetImage(widget.galleryItems[index].image),
|
|
|
|
// initialScale: PhotoViewComputedScale.contained * 0.8,
|
|
|
|
// heroAttributes: PhotoViewHeroAttributes(tag: galleryItems[index].id),
|
|
|
|
// );
|
|
|
|
// },
|
|
|
|
// itemCount: _totalLength,
|
|
|
|
// loadingBuilder: (context, event) => Center(
|
|
|
|
// child: Container(
|
|
|
|
// width: 20.0,
|
|
|
|
// height: 20.0,
|
|
|
|
// child: CircularProgressIndicator(
|
|
|
|
// value: event == null
|
|
|
|
// ? 0
|
|
|
|
// : event.cumulativeBytesLoaded / event.expectedTotalBytes,
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
// // backgroundDecoration: widget.backgroundDecoration,
|
|
|
|
// // pageController: widget.pageController,
|
|
|
|
// // onPageChanged: onPageChanged,
|
|
|
|
// )
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
|
2021-02-21 17:31:03 +00:00
|
|
|
Widget _appLoading(){
|
|
|
|
return Center(
|
|
|
|
child: ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(maxWidth: 500),
|
|
|
|
child: Container(
|
|
|
|
margin: EdgeInsets.fromLTRB(50, 0, 50, 0),
|
2021-02-22 06:37:41 +00:00
|
|
|
height: 370,
|
2021-02-21 17:31:03 +00:00
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
PlatformCircularProgressIndicator()
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-02-11 20:47:42 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-03-01 00:23:41 +00:00
|
|
|
Widget _buildGridView() {
|
|
|
|
MediaQueryData queryData = MediaQuery.of(context);
|
|
|
|
|
2021-03-04 06:06:09 +00:00
|
|
|
// Can change this to change desired image size
|
|
|
|
final int desiredContentWidth = 500;
|
2021-03-01 00:23:41 +00:00
|
|
|
|
2021-03-04 06:06:09 +00:00
|
|
|
return SliverStaggeredGrid.extentBuilder(
|
2021-03-01 00:23:41 +00:00
|
|
|
itemCount: _totalLength,
|
2021-03-04 06:06:09 +00:00
|
|
|
mainAxisSpacing: 4.0,
|
|
|
|
crossAxisSpacing: 4.0,
|
|
|
|
maxCrossAxisExtent: 500 / queryData.devicePixelRatio,
|
|
|
|
staggeredTileBuilder: (int index) => new StaggeredTile.fit(1),
|
2021-03-01 00:23:41 +00:00
|
|
|
itemBuilder: (BuildContext context, int index) {
|
2021-04-06 00:40:23 +00:00
|
|
|
return bloc.getMedia(index, desiredContentWidth);
|
|
|
|
// return _buildCard(index, desiredContentWidth);
|
2021-03-01 00:23:41 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildCard(index, derivedContentWidth) {
|
2021-02-22 03:36:25 +00:00
|
|
|
return FutureBuilder<CachedNetworkImage>(
|
2021-03-01 00:23:41 +00:00
|
|
|
future: bloc.getMedia(index, derivedContentWidth),
|
2021-02-22 03:36:25 +00:00
|
|
|
builder: (context, snapshot) {
|
2021-03-01 00:23:41 +00:00
|
|
|
if (!snapshot.hasData)
|
|
|
|
return SizedBox(width: 500, height: 500);
|
|
|
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
if (_totalLength == bloc.totalMediaItems)
|
|
|
|
return;
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
_totalLength = bloc.totalMediaItems;
|
|
|
|
});
|
|
|
|
});
|
2021-02-22 03:36:25 +00:00
|
|
|
|
|
|
|
return snapshot.data;
|
|
|
|
}
|
2021-02-11 20:47:42 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|