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