Skip to content

Commit

Permalink
displaying images
Browse files Browse the repository at this point in the history
  • Loading branch information
1grzyb1 committed Mar 17, 2024
1 parent a4f3920 commit 9cecd4c
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 46 deletions.
2 changes: 1 addition & 1 deletion lib/data/data_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DataRepositoryImpl implements DataRepository {
final externalVersion = versionHttpResult.data['version'] as int;
final savedVersion = _sharedPrefs.getInt('version') ?? -1;

if (true || externalVersion > savedVersion) {
if (forceUpdate || externalVersion > savedVersion) {
final futures = await Future.wait([
// _apiService.getCities(),
_apiService.getInfo(),
Expand Down
18 changes: 11 additions & 7 deletions lib/data/db/isar/models/city_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ class CityDataModelDb extends CityData {
}

sponsors = groupedByRow.entries.map((entry) {
final sortedByColumn = entry.value..sort((a, b) => a.column.compareTo(b.column));
return sortedByColumn.map((sponsorModelDb) => SponsorModelApi(
id: sponsorModelDb.id!,
row: sponsorModelDb.row,
column: sponsorModelDb.column,
)).toList();
}).toList();
final sortedByColumn = entry.value
..sort((a, b) => a.column.compareTo(b.column));
return sortedByColumn
.map((sponsorModelDb) => SponsorModelApi(
id: sponsorModelDb.sponsorId!,
row: sponsorModelDb.row,
column: sponsorModelDb.column,
))
.toList();
}).toList()
..sort((a, b) => a[0].row.compareTo(b[0].row));
}
}
6 changes: 3 additions & 3 deletions lib/presentation/components/image_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
import 'package:odyssey_mobile/app/themes.dart';

class ImageTile extends StatelessWidget {
const ImageTile(this.path, {this.color = AppColors.pureWhite, Key? key}) : super(key: key);
final String path;
const ImageTile(this.id, {this.color = AppColors.pureWhite, Key? key}) : super(key: key);
final String id;
final Color color;

@override
Expand All @@ -12,7 +12,7 @@ class ImageTile extends StatelessWidget {
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(AppValues.bigBrRadius),
image: DecorationImage(image: AssetImage(path), fit: BoxFit.scaleDown)),
image: DecorationImage(image: NetworkImage('http://grzybek.snet.ovh:8082/sponsor/' + id), fit: BoxFit.scaleDown)),
);
}
}
95 changes: 60 additions & 35 deletions lib/presentation/home_screen/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:odyssey_mobile/app/asset_paths.dart';
import 'package:odyssey_mobile/app/themes.dart';
import 'package:odyssey_mobile/data/api/models/sponsor.dart';
import 'package:odyssey_mobile/presentation/components/image_tile.dart';
import 'package:odyssey_mobile/app/strings.dart';

Expand All @@ -14,27 +15,28 @@ class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
return CityDataBuilder(
onData: (data, _) {
return buildScaffold(size);
}
);
return CityDataBuilder(onData: (data, _) {
return buildScaffold(size, data.sponsors);
});
}

Scaffold buildScaffold(Size size) {
Scaffold buildScaffold(Size size, List<List<SponsorModelApi>> sponsors) {
return Scaffold(
backgroundColor: AppColors.shadowGrey,
appBar: AppBar(title: const Text(AppStrings.homeScreenTitle), centerTitle: true),
appBar: AppBar(
title: const Text(AppStrings.homeScreenTitle), centerTitle: true),
body: CustomScrollView(
cacheExtent: 200,
slivers: [
SliverToBoxAdapter(
child: Column(
children: [
Container(
margin: const EdgeInsets.only(left: 16.0, right: 16.0, top: 16),
margin:
const EdgeInsets.only(left: 16.0, right: 16.0, top: 16),
height: size.width,
child: const ImageTile(AssetPaths.eventLogo, color: AppColors.omerBlue),
child: ImageTile(sponsors[0][0].id.toString(),
color: AppColors.omerBlue),
),
const Padding(
padding: EdgeInsets.all(24.0),
Expand All @@ -47,34 +49,57 @@ class HomeScreen extends StatelessWidget {
],
),
),
SliverToBoxAdapter(
child: Container(
margin: const EdgeInsets.all(16),
height: 120,
child: Row(children: const [
Expanded(child: ImageTile(AssetPaths.sponsor1)),
SizedBox(width: 16),
Expanded(child: ImageTile(AssetPaths.sponsor5)),
]),
),
),
SliverPadding(
padding: const EdgeInsets.only(left: 16.0, right: 16.0, bottom: 16.0),
sliver: SliverGrid(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
childAspectRatio: 1,
crossAxisSpacing: 16,
mainAxisSpacing: 16,
),
delegate: SliverChildBuilderDelegate(
(context, index) => ImageTile(_imageGrid[index]!),
addAutomaticKeepAlives: false,
childCount: 12,
...sponsors.skip(1).map((row) {
return SliverPadding(
padding: EdgeInsets.all(16),
sliver: SliverGrid(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: row.length,
childAspectRatio: 1,
crossAxisSpacing: 16,
mainAxisSpacing: 16,
),
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
if (index < row.length) {
return ImageTile(row[index].id.toString());
}
return null;
},
childCount: row.length,
),
),
),
),
);
}).toList(),
],
// SliverToBoxAdapter(
// child: Container(
// margin: const EdgeInsets.all(16),
// height: 120,
// child: Row(children: const [
// Expanded(child: ImageTile(AssetPaths.sponsor1)),
// SizedBox(width: 16),
// Expanded(child: ImageTile(AssetPaths.sponsor5)),
// ]),
// ),
// ),
// SliverPadding(
// padding:
// const EdgeInsets.only(left: 16.0, right: 16.0, bottom: 16.0),
// sliver: SliverGrid(
// gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
// crossAxisCount: 3,
// childAspectRatio: 1,
// crossAxisSpacing: 16,
// mainAxisSpacing: 16,
// ),
// delegate: SliverChildBuilderDelegate(
// (context, index) => ImageTile(_imageGrid[index]!),
// addAutomaticKeepAlives: false,
// childCount: 12,
// ),
// ),
// ),
));
}
}
Expand Down

0 comments on commit 9cecd4c

Please sign in to comment.