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

ENFIN TINDER MARCHE

parent 6feb322e
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'dart:math';
void main() => runApp(const TindBook());
/// Flutter code sample for [Draggable].
void main() => runApp(const TindBookApp());
class TindBookApp extends StatelessWidget {
const TindBookApp({super.key});
class TindBook extends StatelessWidget {
const TindBook({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
......@@ -15,180 +12,61 @@ class TindBookApp extends StatelessWidget {
create: (context) => TindBookState(),
child: MaterialApp(
title: 'Tind Book',
theme: ThemeData(
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(
home: Scaffold(
appBar: AppBar(title: const Text('Draggable Sample')),
body: MyHomePage(),
),
);
},
body: const MyHomePage(),
),
),
);
}
}
class TindBookState extends ChangeNotifier {
}
class TindBook extends StatefulWidget {
const TindBook({super.key});
@override
State<TindBook> createState() => _TindBookApp();
}
class _TindBookApp extends State<TindBook> {
bool acceptedData = false;
double dragDistance = 0.0;
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
double containerWidth = constraints.maxWidth / 3; // Adjust as needed
double containerHeight = constraints.maxHeight; // Adjust as needed
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
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;
});
},
),
],
);
},
);
// List of image paths
List<String> imagePaths = [
'assets/images/passeur.png',
'assets/images/1.jpg',
'assets/images/2.jpg',
// Add more image paths as needed
];
// Index of the currently displayed image
int currentImageIndex = 0;
// Function to handle swiping in any direction
void handleSwipe(int direction) {
if (direction == 1) {
// Swipe right
if (currentImageIndex < imagePaths.length - 1) {
currentImageIndex++;
notifyListeners();
}
} else {
// Swipe left
if (currentImageIndex > 0) {
currentImageIndex--;
notifyListeners();
}
}
}
// test
class FavoritePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(children: [
Text('Test'),
],)
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
var selectedIndex = 0;
@override
Widget build(BuildContext context) {
Widget page;
switch (selectedIndex) {
case 0:
page = TindBook();
page = TindBookContent();
break;
case 1:
page = FavoritePage();
......@@ -201,13 +79,13 @@ class _MyHomePageState extends State<MyHomePage> {
}
return LayoutBuilder(
builder: (context,constraints) {
builder: (context, constraints) {
return Scaffold(
body: Row(
children: [
SafeArea(
child: NavigationRail(
extended: constraints.maxWidth>=600,
extended: constraints.maxWidth >= 600,
destinations: [
NavigationRailDestination(
icon: Icon(Icons.home),
......@@ -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:
flutter:
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';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const TindBook());
await tester.pumpWidget(const TindBookApp());
// 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