Commit 33cae3e8 authored by Timothé KOBAK's avatar Timothé KOBAK

ça avance

parent 1393677b
...@@ -5,7 +5,7 @@ import 'package:flutter/services.dart' show rootBundle; ...@@ -5,7 +5,7 @@ import 'package:flutter/services.dart' show rootBundle;
const String filePath = '../assets/data.json'; const String filePath = '../assets/data.json';
class TindBookState extends ChangeNotifier { class TindCodeState extends ChangeNotifier {
String input = ""; String input = "";
late var data; late var data;
List<int> favorites = <int>[]; List<int> favorites = <int>[];
......
...@@ -12,7 +12,7 @@ class _FavoritePageState extends State<FavoritePage> { ...@@ -12,7 +12,7 @@ class _FavoritePageState extends State<FavoritePage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
TindBookState state = Provider.of<TindBookState>(context); TindCodeState state = Provider.of<TindCodeState>(context);
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
...@@ -55,7 +55,7 @@ class _FavoritePageState extends State<FavoritePage> { ...@@ -55,7 +55,7 @@ class _FavoritePageState extends State<FavoritePage> {
); );
}, },
child: Padding( child: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(20.0),
child: Image.asset( child: Image.asset(
book['image'], book['image'],
fit: BoxFit.cover, fit: BoxFit.cover,
......
...@@ -5,17 +5,17 @@ import 'favorite_page.dart'; ...@@ -5,17 +5,17 @@ import 'favorite_page.dart';
import 'swipe_page.dart'; import 'swipe_page.dart';
void main() => runApp(const TindBook()); void main() => runApp(const TindCode());
class TindBook extends StatelessWidget { class TindCode extends StatelessWidget {
const TindBook({Key? key}) : super(key: key); const TindCode({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ChangeNotifierProvider( return ChangeNotifierProvider(
create: (context) { create: (context) {
final appState = TindBookState(); final appState = TindCodeState();
appState.loadData(); appState.loadData();
return appState; return appState;
}, },
...@@ -32,10 +32,10 @@ class TindBook extends StatelessWidget { ...@@ -32,10 +32,10 @@ class TindBook extends StatelessWidget {
backgroundColor: Color.fromRGBO(212, 163, 115, 1), // Set navigation rail color backgroundColor: Color.fromRGBO(212, 163, 115, 1), // Set navigation rail color
), ),
), ),
title: 'Tind Book', title: 'Tind Code',
home: Scaffold( home: Scaffold(
appBar: AppBar(title: Text( appBar: AppBar(title: Text(
'Tind Book', 'Tind Code',
style: TextStyle( style: TextStyle(
fontSize: 24, fontSize: 24,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
...@@ -68,7 +68,7 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -68,7 +68,7 @@ class _MyHomePageState extends State<MyHomePage> {
page = FavoritePage(); page = FavoritePage();
break; break;
case 1: case 1:
page = TindBookContent(); page = TindCodeContent();
break; break;
case 2: case 2:
page = Placeholder(); page = Placeholder();
......
...@@ -3,16 +3,15 @@ import 'package:flutter/material.dart'; ...@@ -3,16 +3,15 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'app_state.dart'; import 'app_state.dart';
class TindCodeContent extends StatefulWidget {
class TindBookContent extends StatefulWidget { const TindCodeContent({Key? key}) : super(key: key);
const TindBookContent({Key? key}) : super(key: key);
@override @override
State<TindBookContent> createState() => _TindBookContentState(); State<TindCodeContent> createState() => _TindCodeContentState();
} }
class _TindBookContentState extends State<TindBookContent> { class _TindCodeContentState extends State<TindCodeContent> {
late TindBookState state; late TindCodeState state;
double _startX = 0.0; double _startX = 0.0;
double _currentX = 0.0; double _currentX = 0.0;
double _deltaX = 0.0; double _deltaX = 0.0;
...@@ -23,7 +22,7 @@ class _TindBookContentState extends State<TindBookContent> { ...@@ -23,7 +22,7 @@ class _TindBookContentState extends State<TindBookContent> {
@override @override
void didChangeDependencies() { void didChangeDependencies() {
super.didChangeDependencies(); super.didChangeDependencies();
state = Provider.of<TindBookState>(context); state = Provider.of<TindCodeState>(context);
if (remainingI.contains(-1)){ if (remainingI.contains(-1)){
remainingI = List<int>.generate(state.data.length, (i) => i); remainingI = List<int>.generate(state.data.length, (i) => i);
remainingI.shuffle(); remainingI.shuffle();
...@@ -51,10 +50,21 @@ class _TindBookContentState extends State<TindBookContent> { ...@@ -51,10 +50,21 @@ class _TindBookContentState extends State<TindBookContent> {
} }
// TODO : Change this maybe ?
if (remainingI.length == 0){ if (remainingI.length == 0){
print("no more books"); showDialog(
remainingI = List<int>.generate(state.data.length, (i) => i); context: context,
builder: (_) => NoMoreBooksWidget(),
);
remainingI = List<int>.
generate(state.data.length, (i) => i).
where((i) => ! state.favorites.contains(i)).
toList();
if (remainingI.length==0) {
remainingI = List<int>.
generate(state.data.length, (i) => i);
};
remainingI.shuffle(); remainingI.shuffle();
} }
} }
...@@ -74,7 +84,6 @@ class _TindBookContentState extends State<TindBookContent> { ...@@ -74,7 +84,6 @@ class _TindBookContentState extends State<TindBookContent> {
onHorizontalDragEnd: (details) { onHorizontalDragEnd: (details) {
if (_isSwiping) { if (_isSwiping) {
_isSwiping = false; _isSwiping = false;
print(state.data[currentImageIndex]['image']);
if (_deltaX > 50) { if (_deltaX > 50) {
handleSwipe(1); handleSwipe(1);
showDialog( showDialog(
...@@ -108,13 +117,13 @@ class _TindBookContentState extends State<TindBookContent> { ...@@ -108,13 +117,13 @@ class _TindBookContentState extends State<TindBookContent> {
child: Transform.translate( child: Transform.translate(
offset: Offset(_deltaX, 0.0), offset: Offset(_deltaX, 0.0),
child: Transform.rotate( child: Transform.rotate(
angle: _deltaX * 0.0002, // Adjust the rotation speed here angle: _deltaX * 0.0002,
child: ClipRRect( child: ClipRRect(
borderRadius: BorderRadius.circular(120), // Adjust the radius as needed borderRadius: BorderRadius.circular(120),
child: Image.asset( child: Image.asset(
state.data[currentImageIndex]['image'], state.data[currentImageIndex]['image'],
height: containerHeight / 3, // Adjust image height height: containerHeight / 3,
width: containerWidth / 3, // Adjust image width width: containerWidth / 3,
fit: BoxFit.contain, fit: BoxFit.contain,
), ),
), ),
...@@ -174,6 +183,30 @@ class _TindBookContentState extends State<TindBookContent> { ...@@ -174,6 +183,30 @@ class _TindBookContentState extends State<TindBookContent> {
} }
} }
class NoMoreBooksWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text('No More Media for you'),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('You have swipped all the media'),
Image.asset('assets/images/nobook.jpg',fit: BoxFit.contain,),
],
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('OK'),
),
],
);
}
}
class SwipeFeedback extends StatefulWidget { class SwipeFeedback extends StatefulWidget {
final bool isSwipeRight; final bool isSwipeRight;
...@@ -207,7 +240,7 @@ class _SwipeFeedbackState extends State<SwipeFeedback> with SingleTickerProvider ...@@ -207,7 +240,7 @@ class _SwipeFeedbackState extends State<SwipeFeedback> with SingleTickerProvider
_controller.addStatusListener((status) { _controller.addStatusListener((status) {
if (status == AnimationStatus.completed) { if (status == AnimationStatus.completed) {
_timer = Timer(Duration(milliseconds: 200), () { _timer = Timer(Duration(milliseconds: 200), () {
Navigator.of(context).pop(); // Dismiss the dialog after 500 milliseconds Navigator.of(context).pop();
}); });
} else if (status == AnimationStatus.dismissed) { } else if (status == AnimationStatus.dismissed) {
_controller.dispose(); _controller.dispose();
...@@ -240,7 +273,7 @@ class _SwipeFeedbackState extends State<SwipeFeedback> with SingleTickerProvider ...@@ -240,7 +273,7 @@ class _SwipeFeedbackState extends State<SwipeFeedback> with SingleTickerProvider
@override @override
void dispose() { void dispose() {
_controller.dispose(); _controller.dispose();
_timer.cancel(); // Cancel the timer when disposing the widget _timer.cancel();
super.dispose(); super.dispose();
} }
} }
...@@ -13,7 +13,7 @@ import 'package:tp1/main.dart'; ...@@ -13,7 +13,7 @@ import 'package:tp1/main.dart';
void main() { void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async { testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame. // Build our app and trigger a frame.
await tester.pumpWidget(const TindBookApp()); await tester.pumpWidget(const TindCodeApp());
// Verify that our counter starts at 0. // Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget); expect(find.text('0'), findsOneWidget);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment