Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
amse
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Matis SPINELLI
amse
Commits
a14a2061
Commit
a14a2061
authored
Feb 10, 2024
by
Timothé KOBAK
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ENFIN TINDER MARCHE
parent
6feb322e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
148 additions
and
165 deletions
+148
-165
1.jpg
tp1/assets/images/1.jpg
+0
-0
2.jpg
tp1/assets/images/2.jpg
+0
-0
passeur.png
tp1/assets/images/passeur.png
+0
-0
main.dart
tp1/lib/main.dart
+143
-164
pubspec.yaml
tp1/pubspec.yaml
+4
-0
widget_test.dart
tp1/test/widget_test.dart
+1
-1
No files found.
tp1/assets/images/1.jpg
0 → 100644
View file @
a14a2061
1.34 MB
tp1/assets/images/2.jpg
0 → 100644
View file @
a14a2061
937 KB
tp1/assets/images/passeur.png
0 → 100644
View file @
a14a2061
330 KB
tp1/lib/main.dart
View file @
a14a2061
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
(
appBar:
AppBar
(
title:
const
Text
(
'Draggable Sample'
)),
body:
MyHomePage
(),
),
);
},
home:
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'Draggable Sample'
)),
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
;
});
},
),
],
);
},
);
}
}
// test
class
FavoritePage
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
body:
Column
(
children:
[
Text
(
'Test'
),
],)
);
// 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
();
}
}
}
}
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
=
TindBook
Content
();
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
),
...
...
@@ -217,10 +95,10 @@ class _MyHomePageState extends State<MyHomePage> {
icon:
Icon
(
Icons
.
swipe
),
label:
Text
(
'Swipe'
),
),
NavigationRailDestination
(
NavigationRailDestination
(
icon:
Icon
(
Icons
.
info
),
label:
Text
(
'About'
),
),
),
],
selectedIndex:
selectedIndex
,
onDestinationSelected:
(
value
)
{
...
...
@@ -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'
),
],
),
);
}
}
\ No newline at end of file
}
tp1/pubspec.yaml
View file @
a14a2061
...
...
@@ -23,3 +23,7 @@ dev_dependencies:
flutter
:
uses-material-design
:
true
assets
:
-
assets/images/1.jpg
-
assets/images/2.jpg
-
assets/images/passeur.png
tp1/test/widget_test.dart
View file @
a14a2061
...
...
@@ -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
TindBook
App
());
// Verify that our counter starts at 0.
expect
(
find
.
text
(
'0'
),
findsOneWidget
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment