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
Show 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:flutter/material.dart'
;
import
'package:provider/provider.dart'
;
import
'package:provider/provider.dart'
;
import
'dart:math'
;
import
'dart:math'
;
import
'favorite_page.dart'
;
import
'favorite_page.dart'
;
import
'app_state.dart'
;
import
'app_state.dart'
;
void
main
(
)
=>
runApp
(
const
TindBook
());
void
main
(
)
{
class
TindBook
extends
StatelessWidget
{
runApp
(
MyApp
());
const
TindBook
({
Key
?
key
})
:
super
(
key:
key
);
}
class
MyApp
extends
StatelessWidget
{
const
MyApp
({
super
.
key
});
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
ChangeNotifierProvider
(
return
ChangeNotifierProvider
(
create:
(
context
)
=>
App
State
(),
create:
(
context
)
=>
TindBook
State
(),
child:
MaterialApp
(
child:
MaterialApp
(
title:
'Namer App'
,
theme:
ThemeData
(
theme:
ThemeData
(
useMaterial3:
true
,
primarySwatch:
Colors
.
blue
,
colorScheme:
ColorScheme
.
fromSeed
(
seedColor:
Color
.
fromARGB
(
255
,
Random
().
nextInt
(
255
),
Random
().
nextInt
(
255
),
Random
().
nextInt
(
255
))),
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
{
// Index of the currently displayed image
var
current
=
WordPair
.
random
()
;
int
currentImageIndex
=
0
;
void
getNext
(){
// Function to handle swiping in any direction
current
=
WordPair
.
random
();
void
handleSwipe
(
int
direction
)
{
if
(
direction
==
1
)
{
// Swipe right
if
(
currentImageIndex
<
imagePaths
.
length
-
1
)
{
currentImageIndex
++;
notifyListeners
();
notifyListeners
();
}
}
var
favorites
=
<
WordPair
>[];
void
toggleFavorite
()
{
if
(
favorites
.
contains
(
current
))
{
favorites
.
remove
(
current
);
}
else
{
}
else
{
favorites
.
add
(
current
);
// Swipe left
}
if
(
currentImageIndex
>
0
)
{
currentImageIndex
--;
notifyListeners
();
notifyListeners
();
}
}
}
}
}
}
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
=
GeneratorPage
();
page
=
TindBookContent
();
break
;
break
;
case
1
:
case
1
:
page
=
FavoritePage
();
page
=
FavoritePage
();
break
;
break
;
case
2
:
page
=
Placeholder
();
break
;
default
:
default
:
throw
UnimplementedError
(
'no widget for
$selectedIndex
'
);
throw
UnimplementedError
(
'no widget for
$selectedIndex
'
);
}
}
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
),
label:
Text
(
'Home'
),
label:
Text
(
'Home'
),
),
),
NavigationRailDestination
(
NavigationRailDestination
(
icon:
Icon
(
Icons
.
favorite
),
icon:
Icon
(
Icons
.
swipe
),
label:
Text
(
'Favorites'
),
label:
Text
(
'Swipe'
),
),
NavigationRailDestination
(
icon:
Icon
(
Icons
.
info
),
label:
Text
(
'About'
),
),
),
],
],
selectedIndex:
selectedIndex
,
selectedIndex:
selectedIndex
,
...
@@ -100,90 +124,157 @@ class _MyHomePageState extends State<MyHomePage> {
...
@@ -100,90 +124,157 @@ class _MyHomePageState extends State<MyHomePage> {
},
},
),
),
),
),
VerticalDivider
(
thickness:
1
,
width:
1
,
),
// Add a vertical divider
Expanded
(
Expanded
(
child:
Container
(
child:
Container
(
color:
Theme
.
of
(
context
).
colorScheme
.
primaryContainer
,
color:
Color
.
fromRGBO
(
250
,
237
,
205
,
1
)
,
child:
page
,
child:
page
,
),
),
),
),
],
],
),
),
);
);
}
}
,
);
);
}
}
}
}
class
TindBookContent
extends
StatefulWidget
{
const
TindBookContent
({
Key
?
key
})
:
super
(
key:
key
);
class
GeneratorPage
extends
StatelessWidget
{
@override
@override
Widget
build
(
BuildContext
context
)
{
State
<
TindBookContent
>
createState
()
=>
_TindBookContentState
();
var
appState
=
context
.
watch
<
AppState
>();
}
var
pair
=
appState
.
current
;
IconData
icon
;
class
_TindBookContentState
extends
State
<
TindBookContent
>
{
if
(
appState
.
favorites
.
contains
(
pair
))
{
late
TindBookState
state
;
icon
=
Icons
.
favorite
;
double
_startX
=
0.0
;
}
else
{
double
_currentX
=
0.0
;
icon
=
Icons
.
favorite_border
;
double
_deltaX
=
0.0
;
bool
_isSwiping
=
false
;
@override
void
didChangeDependencies
()
{
super
.
didChangeDependencies
();
state
=
Provider
.
of
<
TindBookState
>(
context
);
}
}
return
Center
(
@override
child:
Column
(
Widget
build
(
BuildContext
context
)
{
mainAxisAlignment:
MainAxisAlignment
.
center
,
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:
[
children:
[
BigCard
(
pair:
pair
),
Positioned
.
fill
(
SizedBox
(
height:
10
),
child:
Container
(
Row
(
color:
Color
.
fromRGBO
(
250
,
237
,
205
,
1
),
mainAxisSize:
MainAxisSize
.
min
,
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
,
),
),
),
),
),
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:
[
children:
[
ElevatedButton
.
icon
(
Text
(
onPressed:
()
{
'Titre du livre '
,
appState
.
toggleFavorite
();
style:
TextStyle
(
},
color:
Colors
.
white
,
icon:
Icon
(
icon
),
fontSize:
20
,
label:
Text
(
'Like'
),
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
,
),
),
SizedBox
(
width:
10
),
ElevatedButton
(
onPressed:
()
{
appState
.
getNext
();
},
child:
Text
(
'Next'
),
),
),
],
],
),
),
),
),
],
],
),
),
);
);
},
);
}
}
}
}
class
FavoritePage
extends
StatelessWidget
{
class
BigCard
extends
StatelessWidget
{
const
BigCard
({
super
.
key
,
required
this
.
pair
,
});
final
WordPair
pair
;
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
final
theme
=
Theme
.
of
(
context
);
return
Scaffold
(
final
style
=
theme
.
textTheme
.
displayMedium
!.
copyWith
(
body:
Column
(
color:
theme
.
colorScheme
.
onPrimary
,
children:
[
);
Text
(
'Test'
),
],
return
Card
(
color:
theme
.
colorScheme
.
primary
,
child:
Padding
(
padding:
const
EdgeInsets
.
all
(
20
),
child:
Text
(
pair
.
asLowerCase
,
style:
style
,
semanticsLabel:
"
${pair.first}
${pair.second}
"
,
),
),
),
);
);
}
}
...
...
tp1/pubspec.yaml
View file @
87a941eb
...
@@ -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 @
87a941eb
...
@@ -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
My
App
());
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