-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change how the thabloids work (#523)
- Loading branch information
1 parent
946f416
commit af5b4f9
Showing
7 changed files
with
98 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:reaxit/api/api_repository.dart'; | ||
import 'package:reaxit/models/thabliod.dart'; | ||
|
||
class ThabloidCubit extends Cubit<Thabloid> { | ||
final ApiRepository api; | ||
Thabloid thabloid; | ||
Timer _debounceTimer = Timer(const Duration(hours: 1), () => {}); | ||
|
||
ThabloidCubit(this.api, this.thabloid) : super(thabloid); | ||
|
||
Future<String> getTitle() async { | ||
if (!_debounceTimer.isActive) { | ||
Thabloid thabloid = await api.getThabloid(pk: this.thabloid.pk); | ||
emit(thabloid); | ||
_debounceTimer = Timer(const Duration(hours: 1), () => {}); | ||
} | ||
return thabloid.file; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,61 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:reaxit/api/api_repository.dart'; | ||
import 'package:reaxit/blocs/thabloid_cubit.dart'; | ||
import 'package:reaxit/models/thabliod.dart'; | ||
import 'package:reaxit/ui/widgets/cached_image.dart'; | ||
import 'package:url_launcher/url_launcher.dart'; | ||
|
||
class ThabloidDetailCard extends StatelessWidget { | ||
final Thabloid thabloid; | ||
final ThabloidCubit cubit; | ||
ThabloidDetailCard(Thabloid thabloid, ApiRepository api) | ||
: cubit = ThabloidCubit(api, thabloid); | ||
|
||
const ThabloidDetailCard(this.thabloid); | ||
|
||
void _openThabloid() { | ||
launchUrl(Uri.parse(thabloid.file), mode: LaunchMode.externalApplication); | ||
void _openThabloid() async { | ||
launchUrl(Uri.parse(await cubit.getTitle()), | ||
mode: LaunchMode.externalApplication); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final textTheme = Theme.of(context).textTheme; | ||
return Stack( | ||
children: [ | ||
CachedImage( | ||
placeholder: 'assets/img/thabloid_placeholder.png', | ||
imageUrl: thabloid.cover, | ||
), | ||
Align( | ||
alignment: Alignment.bottomRight, | ||
child: Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: Text( | ||
'${thabloid.year}-${thabloid.year + 1} nr. ${thabloid.issue}', | ||
maxLines: 1, | ||
overflow: TextOverflow.ellipsis, | ||
style: textTheme.titleMedium?.copyWith(shadows: [ | ||
const Shadow( | ||
offset: Offset(0.0, 0.0), | ||
blurRadius: 10.0, | ||
color: Color.fromARGB(255, 0, 0, 0), | ||
), | ||
]), | ||
return BlocBuilder<ThabloidCubit, Thabloid>( | ||
builder: (context, thabloidsState) { | ||
Thabloid thabloid = thabloidsState; | ||
return Stack( | ||
children: [ | ||
CachedImage( | ||
placeholder: 'assets/img/thabloid_placeholder.png', | ||
imageUrl: thabloid.cover, | ||
), | ||
Align( | ||
alignment: Alignment.bottomRight, | ||
child: Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: Text( | ||
'${thabloid.year}-${thabloid.year + 1} nr. ${thabloid.issue}', | ||
maxLines: 1, | ||
overflow: TextOverflow.ellipsis, | ||
style: textTheme.titleMedium?.copyWith(shadows: [ | ||
const Shadow( | ||
offset: Offset(0.0, 0.0), | ||
blurRadius: 10.0, | ||
color: Color.fromARGB(255, 0, 0, 0), | ||
), | ||
]), | ||
), | ||
), | ||
), | ||
), | ||
Positioned.fill( | ||
child: Material( | ||
color: Colors.transparent, | ||
child: InkWell( | ||
onTap: _openThabloid, | ||
Positioned.fill( | ||
child: Material( | ||
color: Colors.transparent, | ||
child: InkWell( | ||
onTap: _openThabloid, | ||
), | ||
), | ||
), | ||
), | ||
], | ||
); | ||
], | ||
); | ||
}); | ||
} | ||
} |