Commit caea29bb authored by m-spi's avatar m-spi

Merge branch 'tim' into matis

parents e90e42b3 33cae3e8
......@@ -5,7 +5,7 @@ import 'package:flutter/services.dart' show rootBundle;
const String filePath = '../assets/data.json';
class TindBookState extends ChangeNotifier {
class TindCodeState extends ChangeNotifier {
String input = "";
List<dynamic> data = <dynamic>[];
List<int> favorites = <int>[];
......
......@@ -12,7 +12,7 @@ class _FavoritePageState extends State<FavoritePage> {
@override
Widget build(BuildContext context) {
TindBookState state = Provider.of<TindBookState>(context);
TindCodeState state = Provider.of<TindCodeState>(context);
return Scaffold(
appBar: AppBar(
......@@ -55,7 +55,7 @@ class _FavoritePageState extends State<FavoritePage> {
);
},
child: Padding(
padding: const EdgeInsets.all(8.0),
padding: const EdgeInsets.all(20.0),
child: Image.asset(
book['image'],
fit: BoxFit.cover,
......
......@@ -5,17 +5,17 @@ import 'favorite_page.dart';
import 'swipe_page.dart';
void main() => runApp(const TindBook());
void main() => runApp(const TindCode());
class TindBook extends StatelessWidget {
const TindBook({Key? key}) : super(key: key);
class TindCode extends StatelessWidget {
const TindCode({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) {
final appState = TindBookState();
final appState = TindCodeState();
appState.loadData();
return appState;
},
......@@ -32,10 +32,10 @@ class TindBook extends StatelessWidget {
backgroundColor: Color.fromRGBO(212, 163, 115, 1), // Set navigation rail color
),
),
title: 'Tind Book',
title: 'Tind Code',
home: Scaffold(
appBar: AppBar(title: Text(
'Tind Book',
'Tind Code',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
......@@ -68,7 +68,7 @@ class _MyHomePageState extends State<MyHomePage> {
page = FavoritePage();
break;
case 1:
page = TindBookContent();
page = TindCodeContent();
break;
case 2:
page = Placeholder();
......
......@@ -3,16 +3,15 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'app_state.dart';
class TindBookContent extends StatefulWidget {
const TindBookContent({Key? key}) : super(key: key);
class TindCodeContent extends StatefulWidget {
const TindCodeContent({Key? key}) : super(key: key);
@override
State<TindBookContent> createState() => _TindBookContentState();
State<TindCodeContent> createState() => _TindCodeContentState();
}
class _TindBookContentState extends State<TindBookContent> {
late TindBookState state;
class _TindCodeContentState extends State<TindCodeContent> {
late TindCodeState state;
double _startX = 0.0;
double _currentX = 0.0;
double _deltaX = 0.0;
......@@ -23,7 +22,7 @@ class _TindBookContentState extends State<TindBookContent> {
@override
void didChangeDependencies() {
super.didChangeDependencies();
state = Provider.of<TindBookState>(context);
state = Provider.of<TindCodeState>(context);
if (remainingI.contains(-1)){
remainingI = List<int>.generate(state.data.length, (i) => i);
remainingI.shuffle();
......@@ -51,10 +50,21 @@ class _TindBookContentState extends State<TindBookContent> {
}
// TODO : Change this maybe ?
if (remainingI.length == 0){
print("no more books");
remainingI = List<int>.generate(state.data.length, (i) => i);
showDialog(
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();
}
}
......@@ -74,7 +84,6 @@ class _TindBookContentState extends State<TindBookContent> {
onHorizontalDragEnd: (details) {
if (_isSwiping) {
_isSwiping = false;
print(state.data[currentImageIndex]['image']);
if (_deltaX > 50) {
handleSwipe(1);
showDialog(
......@@ -108,13 +117,13 @@ class _TindBookContentState extends State<TindBookContent> {
child: Transform.translate(
offset: Offset(_deltaX, 0.0),
child: Transform.rotate(
angle: _deltaX * 0.0002, // Adjust the rotation speed here
angle: _deltaX * 0.0002,
child: ClipRRect(
borderRadius: BorderRadius.circular(120), // Adjust the radius as needed
borderRadius: BorderRadius.circular(120),
child: Image.asset(
state.data[currentImageIndex]['image'],
height: containerHeight / 3, // Adjust image height
width: containerWidth / 3, // Adjust image width
height: containerHeight / 3,
width: containerWidth / 3,
fit: BoxFit.contain,
),
),
......@@ -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 {
final bool isSwipeRight;
......@@ -207,7 +240,7 @@ class _SwipeFeedbackState extends State<SwipeFeedback> with SingleTickerProvider
_controller.addStatusListener((status) {
if (status == AnimationStatus.completed) {
_timer = Timer(Duration(milliseconds: 200), () {
Navigator.of(context).pop(); // Dismiss the dialog after 500 milliseconds
Navigator.of(context).pop();
});
} else if (status == AnimationStatus.dismissed) {
_controller.dispose();
......@@ -240,7 +273,7 @@ class _SwipeFeedbackState extends State<SwipeFeedback> with SingleTickerProvider
@override
void dispose() {
_controller.dispose();
_timer.cancel(); // Cancel the timer when disposing the widget
_timer.cancel();
super.dispose();
}
}
......@@ -13,7 +13,7 @@ import 'package:tp1/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const TindBookApp());
await tester.pumpWidget(const TindCodeApp());
// Verify that our counter starts at 0.
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