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
33cae3e8
Commit
33cae3e8
authored
Feb 12, 2024
by
Timothé KOBAK
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ça avance
parent
1393677b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
61 additions
and
28 deletions
+61
-28
nobook.jpg
tp1/assets/images/nobook.jpg
+0
-0
nobook.png
tp1/assets/images/nobook.png
+0
-0
app_state.dart
tp1/lib/app_state.dart
+1
-1
favorite_page.dart
tp1/lib/favorite_page.dart
+2
-2
main.dart
tp1/lib/main.dart
+7
-7
swipe_page.dart
tp1/lib/swipe_page.dart
+50
-17
widget_test.dart
tp1/test/widget_test.dart
+1
-1
No files found.
tp1/assets/images/nobook.jpg
0 → 100644
View file @
33cae3e8
114 KB
tp1/assets/images/nobook.png
0 → 100644
View file @
33cae3e8
690 KB
tp1/lib/app_state.dart
View file @
33cae3e8
...
...
@@ -5,7 +5,7 @@ import 'package:flutter/services.dart' show rootBundle;
const
String
filePath
=
'../assets/data.json'
;
class
Tind
Book
State
extends
ChangeNotifier
{
class
Tind
Code
State
extends
ChangeNotifier
{
String
input
=
""
;
late
var
data
;
List
<
int
>
favorites
=
<
int
>[];
...
...
tp1/lib/favorite_page.dart
View file @
33cae3e8
...
...
@@ -12,7 +12,7 @@ class _FavoritePageState extends State<FavoritePage> {
@override
Widget
build
(
BuildContext
context
)
{
Tind
BookState
state
=
Provider
.
of
<
TindBook
State
>(
context
);
Tind
CodeState
state
=
Provider
.
of
<
TindCode
State
>(
context
);
return
Scaffold
(
appBar:
AppBar
(
...
...
@@ -55,7 +55,7 @@ class _FavoritePageState extends State<FavoritePage> {
);
},
child:
Padding
(
padding:
const
EdgeInsets
.
all
(
8
.0
),
padding:
const
EdgeInsets
.
all
(
20
.0
),
child:
Image
.
asset
(
book
[
'image'
],
fit:
BoxFit
.
cover
,
...
...
tp1/lib/main.dart
View file @
33cae3e8
...
...
@@ -5,17 +5,17 @@ import 'favorite_page.dart';
import
'swipe_page.dart'
;
void
main
(
)
=>
runApp
(
const
Tind
Book
());
void
main
(
)
=>
runApp
(
const
Tind
Code
());
class
Tind
Book
extends
StatelessWidget
{
const
Tind
Book
({
Key
?
key
})
:
super
(
key:
key
);
class
Tind
Code
extends
StatelessWidget
{
const
Tind
Code
({
Key
?
key
})
:
super
(
key:
key
);
@override
Widget
build
(
BuildContext
context
)
{
return
ChangeNotifierProvider
(
create:
(
context
)
{
final
appState
=
Tind
Book
State
();
final
appState
=
Tind
Code
State
();
appState
.
loadData
();
return
appState
;
},
...
...
@@ -32,10 +32,10 @@ class TindBook extends StatelessWidget {
backgroundColor:
Color
.
fromRGBO
(
212
,
163
,
115
,
1
),
// Set navigation rail color
),
),
title:
'Tind
Book
'
,
title:
'Tind
Code
'
,
home:
Scaffold
(
appBar:
AppBar
(
title:
Text
(
'Tind
Book
'
,
'Tind
Code
'
,
style:
TextStyle
(
fontSize:
24
,
fontWeight:
FontWeight
.
bold
,
...
...
@@ -68,7 +68,7 @@ class _MyHomePageState extends State<MyHomePage> {
page
=
FavoritePage
();
break
;
case
1
:
page
=
Tind
Book
Content
();
page
=
Tind
Code
Content
();
break
;
case
2
:
page
=
Placeholder
();
...
...
tp1/lib/swipe_page.dart
View file @
33cae3e8
...
...
@@ -3,16 +3,15 @@ import 'package:flutter/material.dart';
import
'package:provider/provider.dart'
;
import
'app_state.dart'
;
class
TindBookContent
extends
StatefulWidget
{
const
TindBookContent
({
Key
?
key
})
:
super
(
key:
key
);
class
TindCodeContent
extends
StatefulWidget
{
const
TindCodeContent
({
Key
?
key
})
:
super
(
key:
key
);
@override
State
<
Tind
BookContent
>
createState
()
=>
_TindBook
ContentState
();
State
<
Tind
CodeContent
>
createState
()
=>
_TindCode
ContentState
();
}
class
_Tind
BookContentState
extends
State
<
TindBook
Content
>
{
late
Tind
Book
State
state
;
class
_Tind
CodeContentState
extends
State
<
TindCode
Content
>
{
late
Tind
Code
State
state
;
double
_startX
=
0.0
;
double
_currentX
=
0.0
;
double
_deltaX
=
0.0
;
...
...
@@ -23,7 +22,7 @@ class _TindBookContentState extends State<TindBookContent> {
@override
void
didChangeDependencies
()
{
super
.
didChangeDependencies
();
state
=
Provider
.
of
<
Tind
Book
State
>(
context
);
state
=
Provider
.
of
<
Tind
Code
State
>(
context
);
if
(
remainingI
.
contains
(-
1
)){
remainingI
=
List
<
int
>.
generate
(
state
.
data
.
length
,
(
i
)
=>
i
);
remainingI
.
shuffle
();
...
...
@@ -51,10 +50,21 @@ class _TindBookContentState extends State<TindBookContent> {
}
// TODO : Change this maybe ?
if
(
remainingI
.
length
==
0
){
print
(
"no more books"
);
remainingI
=
List
<
int
>.
generate
(
state
.
data
.
length
,
(
i
)
=>
i
);
showDialog
(
context:
context
,
builder:
(
_
)
=>
NoMoreBooksWidget
(),
);
remainingI
=
List
<
int
>.
generate
(
state
.
data
.
length
,
(
i
)
=>
i
).
where
((
i
)
=>
!
state
.
favorites
.
contains
(
i
)).
toList
();
if
(
remainingI
.
length
==
0
)
{
remainingI
=
List
<
int
>.
generate
(
state
.
data
.
length
,
(
i
)
=>
i
);
};
remainingI
.
shuffle
();
}
}
...
...
@@ -74,7 +84,6 @@ class _TindBookContentState extends State<TindBookContent> {
onHorizontalDragEnd:
(
details
)
{
if
(
_isSwiping
)
{
_isSwiping
=
false
;
print
(
state
.
data
[
currentImageIndex
][
'image'
]);
if
(
_deltaX
>
50
)
{
handleSwipe
(
1
);
showDialog
(
...
...
@@ -108,13 +117,13 @@ class _TindBookContentState extends State<TindBookContent> {
child:
Transform
.
translate
(
offset:
Offset
(
_deltaX
,
0.0
),
child:
Transform
.
rotate
(
angle:
_deltaX
*
0.0002
,
// Adjust the rotation speed here
angle:
_deltaX
*
0.0002
,
child:
ClipRRect
(
borderRadius:
BorderRadius
.
circular
(
120
),
// Adjust the radius as needed
borderRadius:
BorderRadius
.
circular
(
120
),
child:
Image
.
asset
(
state
.
data
[
currentImageIndex
][
'image'
],
height:
containerHeight
/
3
,
// Adjust image height
width:
containerWidth
/
3
,
// Adjust image width
height:
containerHeight
/
3
,
width:
containerWidth
/
3
,
fit:
BoxFit
.
contain
,
),
),
...
...
@@ -174,6 +183,30 @@ class _TindBookContentState extends State<TindBookContent> {
}
}
class
NoMoreBooksWidget
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
return
AlertDialog
(
title:
Text
(
'No More Media for you'
),
content:
Column
(
mainAxisSize:
MainAxisSize
.
min
,
children:
[
Text
(
'You have swipped all the media'
),
Image
.
asset
(
'assets/images/nobook.jpg'
,
fit:
BoxFit
.
contain
,),
],
),
actions:
[
TextButton
(
onPressed:
()
{
Navigator
.
of
(
context
).
pop
();
},
child:
Text
(
'OK'
),
),
],
);
}
}
class
SwipeFeedback
extends
StatefulWidget
{
final
bool
isSwipeRight
;
...
...
@@ -207,7 +240,7 @@ class _SwipeFeedbackState extends State<SwipeFeedback> with SingleTickerProvider
_controller
.
addStatusListener
((
status
)
{
if
(
status
==
AnimationStatus
.
completed
)
{
_timer
=
Timer
(
Duration
(
milliseconds:
200
),
()
{
Navigator
.
of
(
context
).
pop
();
// Dismiss the dialog after 500 milliseconds
Navigator
.
of
(
context
).
pop
();
});
}
else
if
(
status
==
AnimationStatus
.
dismissed
)
{
_controller
.
dispose
();
...
...
@@ -240,7 +273,7 @@ class _SwipeFeedbackState extends State<SwipeFeedback> with SingleTickerProvider
@override
void
dispose
()
{
_controller
.
dispose
();
_timer
.
cancel
();
// Cancel the timer when disposing the widget
_timer
.
cancel
();
super
.
dispose
();
}
}
tp1/test/widget_test.dart
View file @
33cae3e8
...
...
@@ -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
Tind
Book
App
());
await
tester
.
pumpWidget
(
const
Tind
Code
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