Commit a14a2061 authored by Timothé KOBAK's avatar Timothé KOBAK

ENFIN TINDER MARCHE

parent 6feb322e
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'dart:math';
void main() => runApp(const TindBook());
/// Flutter code sample for [Draggable]. class TindBook extends StatelessWidget {
const TindBook({Key? key}) : super(key: key);
void main() => runApp(const TindBookApp());
class TindBookApp extends StatelessWidget {
const TindBookApp({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -15,180 +12,61 @@ class TindBookApp extends StatelessWidget { ...@@ -15,180 +12,61 @@ class TindBookApp extends StatelessWidget {
create: (context) => TindBookState(), create: (context) => TindBookState(),
child: MaterialApp( child: MaterialApp(
title: 'Tind Book', title: 'Tind Book',
theme: ThemeData( home: Scaffold(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(seedColor:Color.fromARGB(255, Random().nextInt(255), Random().nextInt(255), Random().nextInt(255))),
),
home: Builder(
builder: (context) {
return Directionality(
textDirection: TextDirection.ltr, // or TextDirection.rtl
child: Scaffold(
appBar: AppBar(title: const Text('Draggable Sample')), appBar: AppBar(title: const Text('Draggable Sample')),
body: MyHomePage(), body: const MyHomePage(),
),
);
},
), ),
), ),
); );
} }
} }
class TindBookState extends ChangeNotifier { class TindBookState extends ChangeNotifier {
// List of image paths
} List<String> imagePaths = [
'assets/images/passeur.png',
class TindBook extends StatefulWidget { 'assets/images/1.jpg',
const TindBook({super.key}); 'assets/images/2.jpg',
// Add more image paths as needed
@override ];
State<TindBook> createState() => _TindBookApp();
} // Index of the currently displayed image
int currentImageIndex = 0;
class _TindBookApp extends State<TindBook> {
bool acceptedData = false; // Function to handle swiping in any direction
double dragDistance = 0.0; void handleSwipe(int direction) {
if (direction == 1) {
@override // Swipe right
Widget build(BuildContext context) { if (currentImageIndex < imagePaths.length - 1) {
return LayoutBuilder( currentImageIndex++;
builder: (context, constraints) { notifyListeners();
double containerWidth = constraints.maxWidth / 3; // Adjust as needed }
double containerHeight = constraints.maxHeight; // Adjust as needed } else {
// Swipe left
return Row( if (currentImageIndex > 0) {
mainAxisAlignment: MainAxisAlignment.spaceEvenly, currentImageIndex--;
children: <Widget>[ notifyListeners();
DragTarget<bool>( }
builder: (
BuildContext context,
List<dynamic> accepted,
List<dynamic> rejected,
) {
return Container(
height: containerHeight,
width: containerWidth,
color: Colors.cyan,
child: Center(
child: Text('Value is updated to: $acceptedData'),
),
);
},
onAccept: (bool data) {
setState(() {
acceptedData = data;
acceptedData = false;
});
},
),
GestureDetector(
onHorizontalDragUpdate: (details) {
setState(() {
print('selected: ${details.primaryDelta}');
dragDistance = details.primaryDelta!;
});
},
child: Draggable<bool>(
// Data is the value this Draggable stores.
data: true,
feedback: AnimatedContainer(
duration: Duration(milliseconds: 4), // No animation for feedback
transform: Matrix4.rotationZ(dragDistance*50),
child: Container(
color: Colors.deepOrange,
height: containerHeight,
width: containerWidth,
child: const Icon(Icons.directions_run),
),
),
childWhenDragging: Container(
height: containerHeight,
width: containerWidth,
color: Colors.pinkAccent,
child: const Center(
child: Text('Child When Dragging'),
),
),
child: Container(
height: containerHeight,
width: containerWidth,
color: const Color.fromARGB(255, 255, 89, 89),
child: const Center(
child: Text('Draggable'),
),
),
),
),
DragTarget<bool>(
builder: (
BuildContext context,
List<dynamic> accepted,
List<dynamic> rejected,
) {
return Container(
height: containerHeight,
width: containerWidth,
color: Colors.cyan,
child: Center(
child: Text('Value is updated to: $acceptedData'),
),
);
},
onAccept: (bool data) {
setState(() {
acceptedData = data;
});
},
),
],
);
},
);
} }
}
// test
class FavoritePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(children: [
Text('Test'),
],)
);
} }
} }
class MyHomePage extends StatefulWidget { class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override @override
State<MyHomePage> createState() => _MyHomePageState(); State<MyHomePage> createState() => _MyHomePageState();
} }
class _MyHomePageState extends State<MyHomePage> { class _MyHomePageState extends State<MyHomePage> {
var selectedIndex = 0; var selectedIndex = 0;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Widget page; Widget page;
switch (selectedIndex) { switch (selectedIndex) {
case 0: case 0:
page = TindBook(); page = TindBookContent();
break; break;
case 1: case 1:
page = FavoritePage(); page = FavoritePage();
...@@ -201,13 +79,13 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -201,13 +79,13 @@ class _MyHomePageState extends State<MyHomePage> {
} }
return LayoutBuilder( return LayoutBuilder(
builder: (context,constraints) { builder: (context, constraints) {
return Scaffold( return Scaffold(
body: Row( body: Row(
children: [ children: [
SafeArea( SafeArea(
child: NavigationRail( child: NavigationRail(
extended: constraints.maxWidth>=600, extended: constraints.maxWidth >= 600,
destinations: [ destinations: [
NavigationRailDestination( NavigationRailDestination(
icon: Icon(Icons.home), icon: Icon(Icons.home),
...@@ -240,7 +118,108 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -240,7 +118,108 @@ class _MyHomePageState extends State<MyHomePage> {
], ],
), ),
); );
},
);
}
}
class TindBookContent extends StatefulWidget {
const TindBookContent({Key? key}) : super(key: key);
@override
State<TindBookContent> createState() => _TindBookContentState();
}
class _TindBookContentState extends State<TindBookContent> {
late TindBookState state;
double _startX = 0.0;
double _currentX = 0.0;
double _deltaX = 0.0;
bool _isSwiping = false;
@override
void didChangeDependencies() {
super.didChangeDependencies();
state = Provider.of<TindBookState>(context);
}
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
double containerWidth = constraints.maxWidth;
double containerHeight = constraints.maxHeight;
return GestureDetector(
onHorizontalDragStart: (details) {
_startX = details.globalPosition.dx;
_isSwiping = true;
},
onHorizontalDragUpdate: (details) {
if (_isSwiping) {
_currentX = details.globalPosition.dx;
_deltaX = _currentX - _startX;
setState(() {});
}
},
onHorizontalDragEnd: (details) {
if (_isSwiping) {
_isSwiping = false;
if (_deltaX > 50) {
// Droite
state.handleSwipe(1);
} else if (_deltaX < -50) {
//Gauche
state.handleSwipe(-1);
}
}
_startX = 0.0;
_currentX = 0.0;
_deltaX = 0.0;
},
child: Stack(
children: [
Positioned.fill(
child: Container(
color: Colors.deepOrange,
height: containerHeight,
width: containerWidth,
),
),
Positioned(
top: 0,
left: 0,
right: 0,
bottom: 0,
child: Transform.translate(
offset: Offset(_deltaX, 0.0),
child: Transform.rotate(
angle: _deltaX * 0.0002,
child: Image.asset(
state.imagePaths[state.currentImageIndex],
height: containerHeight,
width: containerWidth,
),
),
),
),
],
),
);
},
);
} }
}
class FavoritePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Text('Test'),
],
),
); );
} }
} }
...@@ -23,3 +23,7 @@ dev_dependencies: ...@@ -23,3 +23,7 @@ dev_dependencies:
flutter: flutter:
uses-material-design: true uses-material-design: true
assets:
- assets/images/1.jpg
- assets/images/2.jpg
- assets/images/passeur.png
...@@ -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 TindBook()); await tester.pumpWidget(const TindBookApp());
// 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