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
Show 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
This diff is collapsed.
Click to expand it.
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: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
=
TindBook
Content
();
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'
),
],
),
);
);
}
}
}
}
tp1/pubspec.yaml
View file @
a14a2061
...
@@ -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
tp1/test/widget_test.dart
View file @
a14a2061
...
@@ -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
TindBook
App
());
// Verify that our counter starts at 0.
// Verify that our counter starts at 0.
expect
(
find
.
text
(
'0'
),
findsOneWidget
);
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