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
87a941eb
Commit
87a941eb
authored
Feb 10, 2024
by
m-spi
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'tim' into matis
parents
dc5cd0b9
f97716bd
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
186 additions
and
91 deletions
+186
-91
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
+181
-90
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 @
87a941eb
1.34 MB
tp1/assets/images/2.jpg
0 → 100644
View file @
87a941eb
937 KB
tp1/assets/images/passeur.png
0 → 100644
View file @
87a941eb
330 KB
tp1/lib/main.dart
View file @
87a941eb
import
'package:english_words/english_words.dart'
;
import
'package:flutter/material.dart'
;
import
'package:provider/provider.dart'
;
import
'dart:math'
;
import
'favorite_page.dart'
;
import
'app_state.dart'
;
void
main
(
)
=>
runApp
(
const
TindBook
());
void
main
(
)
{
runApp
(
MyApp
());
}
class
MyApp
extends
StatelessWidget
{
const
MyApp
({
super
.
key
});
class
TindBook
extends
StatelessWidget
{
const
TindBook
({
Key
?
key
})
:
super
(
key:
key
);
@override
Widget
build
(
BuildContext
context
)
{
return
ChangeNotifierProvider
(
create:
(
context
)
=>
App
State
(),
create:
(
context
)
=>
TindBook
State
(),
child:
MaterialApp
(
title:
'Namer App'
,
theme:
ThemeData
(
useMaterial3:
true
,
colorScheme:
ColorScheme
.
fromSeed
(
seedColor:
Color
.
fromARGB
(
255
,
Random
().
nextInt
(
255
),
Random
().
nextInt
(
255
),
Random
().
nextInt
(
255
))),
primarySwatch:
Colors
.
blue
,
primaryColor:
Color
.
fromRGBO
(
204
,
213
,
174
,
1
),
backgroundColor:
Color
.
fromRGBO
(
233
,
237
,
201
,
1
),
scaffoldBackgroundColor:
Color
.
fromRGBO
(
254
,
250
,
224
,
1
),
appBarTheme:
AppBarTheme
(
backgroundColor:
Color
.
fromRGBO
(
204
,
213
,
174
,
1
),
// Set app bar color
),
navigationRailTheme:
NavigationRailThemeData
(
backgroundColor:
Color
.
fromRGBO
(
212
,
163
,
115
,
1
),
// Set navigation rail color
),
),
title:
'Tind Book'
,
home:
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'Draggable Sample'
)),
body:
const
MyHomePage
(),
),
home:
MyHomePage
(),
),
);
}
}
class
TindBookState
extends
ChangeNotifier
{
// 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
];
class
MyAppState
extends
ChangeNotifier
{
var
current
=
WordPair
.
random
();
void
getNext
(){
current
=
WordPair
.
random
();
notifyListeners
();
}
var
favorites
=
<
WordPair
>[];
// Index of the currently displayed image
int
currentImageIndex
=
0
;
void
toggleFavorite
()
{
if
(
favorites
.
contains
(
current
))
{
favorites
.
remove
(
current
);
// Function to handle swiping in any direction
void
handleSwipe
(
int
direction
)
{
if
(
direction
==
1
)
{
// Swipe right
if
(
currentImageIndex
<
imagePaths
.
length
-
1
)
{
currentImageIndex
++;
notifyListeners
();
}
}
else
{
favorites
.
add
(
current
);
// Swipe left
if
(
currentImageIndex
>
0
)
{
currentImageIndex
--;
notifyListeners
();
}
}
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
=
GeneratorPage
();
page
=
TindBookContent
();
break
;
case
1
:
page
=
FavoritePage
();
break
;
case
2
:
page
=
Placeholder
();
break
;
default
:
throw
UnimplementedError
(
'no widget for
$selectedIndex
'
);
}
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
),
label:
Text
(
'Home'
),
),
NavigationRailDestination
(
icon:
Icon
(
Icons
.
favorite
),
label:
Text
(
'Favorites'
),
icon:
Icon
(
Icons
.
swipe
),
label:
Text
(
'Swipe'
),
),
NavigationRailDestination
(
icon:
Icon
(
Icons
.
info
),
label:
Text
(
'About'
),
),
],
selectedIndex:
selectedIndex
,
...
...
@@ -100,90 +124,157 @@ class _MyHomePageState extends State<MyHomePage> {
},
),
),
VerticalDivider
(
thickness:
1
,
width:
1
,
),
// Add a vertical divider
Expanded
(
child:
Container
(
color:
Theme
.
of
(
context
).
colorScheme
.
primaryContainer
,
color:
Color
.
fromRGBO
(
250
,
237
,
205
,
1
)
,
child:
page
,
),
),
],
),
);
}
}
,
);
}
}
class
TindBookContent
extends
StatefulWidget
{
const
TindBookContent
({
Key
?
key
})
:
super
(
key:
key
);
class
GeneratorPage
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
var
appState
=
context
.
watch
<
AppState
>();
var
pair
=
appState
.
current
;
State
<
TindBookContent
>
createState
()
=>
_TindBookContentState
();
}
IconData
icon
;
if
(
appState
.
favorites
.
contains
(
pair
))
{
icon
=
Icons
.
favorite
;
}
else
{
icon
=
Icons
.
favorite_border
;
}
class
_TindBookContentState
extends
State
<
TindBookContent
>
{
late
TindBookState
state
;
double
_startX
=
0.0
;
double
_currentX
=
0.0
;
double
_deltaX
=
0.0
;
bool
_isSwiping
=
false
;
return
Center
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
BigCard
(
pair:
pair
),
SizedBox
(
height:
10
),
Row
(
mainAxisSize:
MainAxisSize
.
min
,
@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
)
{
// Swipe right
state
.
handleSwipe
(
1
);
}
else
if
(
_deltaX
<
-
50
)
{
// Swipe left
state
.
handleSwipe
(-
1
);
}
}
_startX
=
0.0
;
_currentX
=
0.0
;
_deltaX
=
0.0
;
},
child:
Stack
(
children:
[
ElevatedButton
.
icon
(
onPressed:
()
{
appState
.
toggleFavorite
();
},
icon:
Icon
(
icon
),
label:
Text
(
'Like'
),
Positioned
.
fill
(
child:
Container
(
color:
Color
.
fromRGBO
(
250
,
237
,
205
,
1
),
height:
containerHeight
/
3
,
width:
containerWidth
/
3
,
),
),
Positioned
(
top:
0
,
left:
0
,
right:
0
,
bottom:
0
,
child:
Transform
.
translate
(
offset:
Offset
(
_deltaX
,
0.0
),
child:
Transform
.
rotate
(
angle:
_deltaX
*
0.0002
,
// Adjust the rotation speed here
child:
ClipRRect
(
borderRadius:
BorderRadius
.
circular
(
100
),
// Adjust the radius as needed
child:
Image
.
asset
(
state
.
imagePaths
[
state
.
currentImageIndex
],
height:
containerHeight
/
3
,
// Adjust image height
width:
containerWidth
/
3
,
// Adjust image width
fit:
BoxFit
.
contain
,
),
),
),
),
),
SizedBox
(
width:
10
),
ElevatedButton
(
onPressed:
()
{
appState
.
getNext
();
},
child:
Text
(
'Next'
),
Positioned
(
top:
20
,
left:
20
,
right:
20
,
child:
Container
(
padding:
EdgeInsets
.
all
(
10
),
decoration:
BoxDecoration
(
color:
Colors
.
black
.
withOpacity
(
0.5
),
borderRadius:
BorderRadius
.
circular
(
10
),
),
child:
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
[
Text
(
'Titre du livre '
,
style:
TextStyle
(
color:
Colors
.
white
,
fontSize:
20
,
fontWeight:
FontWeight
.
bold
,
),
),
SizedBox
(
height:
5
),
Text
(
'un tres bon livre qui parle de beaucoup chose , notamment mais aussi de lorem ipsum dolor sit amet a m Doctrine est pas de '
,
style:
TextStyle
(
color:
Colors
.
white
,
fontSize:
16
,
),
),
],
),
),
),
],
),
],
)
,
);
}
,
);
}
}
class
BigCard
extends
StatelessWidget
{
const
BigCard
({
super
.
key
,
required
this
.
pair
,
});
final
WordPair
pair
;
class
FavoritePage
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
final
theme
=
Theme
.
of
(
context
);
final
style
=
theme
.
textTheme
.
displayMedium
!.
copyWith
(
color:
theme
.
colorScheme
.
onPrimary
,
);
return
Card
(
color:
theme
.
colorScheme
.
primary
,
child:
Padding
(
padding:
const
EdgeInsets
.
all
(
20
),
child:
Text
(
pair
.
asLowerCase
,
style:
style
,
semanticsLabel:
"
${pair.first}
${pair.second}
"
,
),
return
Scaffold
(
body:
Column
(
children:
[
Text
(
'Test'
),
],
),
);
}
...
...
tp1/pubspec.yaml
View file @
87a941eb
...
...
@@ -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 @
87a941eb
...
...
@@ -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
My
App
());
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