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
dc5cd0b9
Commit
dc5cd0b9
authored
Feb 10, 2024
by
m-spi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
base for favorite page and appstate
parent
6a2d4880
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
58 deletions
+75
-58
app_state.dart
tp1/lib/app_state.dart
+28
-9
favorite_page.dart
tp1/lib/favorite_page.dart
+35
-15
main.dart
tp1/lib/main.dart
+4
-26
pubspec.lock
tp1/pubspec.lock
+8
-8
No files found.
tp1/lib/app_state.dart
View file @
dc5cd0b9
import
'dart:convert'
;
import
'dart:convert'
;
import
'dart:io'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
show
rootBundle
;
import
'package:english_words/english_words.dart'
;
const
String
filePath
=
'../assets/data.json'
;
const
String
filePath
=
'../assets/data.json'
;
class
AppState
extends
ChangeNotifier
{
class
AppState
extends
ChangeNotifier
{
final
input
;
var
input
=
""
;
final
data
;
var
data
=
""
;
var
jfavorites
=
<
dynamic
>[];
const
AppState
(
var
input
,
var
data
):
Future
<
String
>
loadData
()
async
{
input
=
await
File
(
filePath
).
readAsString
(),
input
=
await
rootBundle
.
loadString
(
filePath
);
data
=
jsonDecode
(
input
).
books
;
data
=
jsonDecode
(
input
);
return
data
;
}
// Implémenter fonction getData
// Implémenter fonction getData
var
favorites
=
<
dynamic
>[];
void
addToFav
(
dynamic
obj
){
void
addToFav
(
dynamic
obj
){
favorites
[]
=
obj
jfavorites
.
add
(
obj
);
}
var
current
=
WordPair
.
random
();
void
getNext
(){
current
=
WordPair
.
random
();
notifyListeners
();
}
var
favorites
=
<
WordPair
>[];
void
toggleFavorite
()
{
if
(
favorites
.
contains
(
current
))
{
favorites
.
remove
(
current
);
}
else
{
favorites
.
add
(
current
);
}
notifyListeners
();
}
}
}
}
tp1/lib/favorite_page.dart
View file @
dc5cd0b9
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:provider/provider.dart'
;
import
'app_state.dart'
;
import
'app_state.dart'
;
...
@@ -7,29 +8,48 @@ class FavoritePage extends StatelessWidget {
...
@@ -7,29 +8,48 @@ class FavoritePage extends StatelessWidget {
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
var
appState
=
context
.
watch
<
AppState
>();
var
appState
=
context
.
watch
<
AppState
>();
var
favorites
=
appState
.
favorites
;
var
favorites
=
appState
.
j
favorites
;
return
LayoutBuilder
(
builder:
(
context
,
constraints
)
{
return
LayoutBuilder
(
builder:
(
context
,
constraints
)
{
return
Scaffold
(
body:
ListView
.
builder
(
return
Scaffold
(
b
ackgroundColor:
Colors
.
red
[
200
],
b
ody:
ListView
.
builder
(
padding:
const
EdgeInsets
.
all
(
8
),
padding:
const
EdgeInsets
.
all
(
8
),
color:
Color
.
red
[
200
],
itemCount:
favorites
.
length
,
itemCount:
favorites
.
length
,
itemBuilder:
(
BuildContext
context
,
int
index
){
itemBuilder:
(
BuildContext
context
,
int
index
){
return
Container
(
return
ListView
(
padding:
const
EdgeInsets
.
all
(
8
),
padding:
const
EdgeInsets
.
all
(
8
),
color:
index
%
2
==
0
?
Color
.
red
[
500
]
:
Color
.
red
[
400
],
children:
<
Widget
>[
children:
<
Widget
>[
Text
(
favorites
[
index
][
'title'
]),
Container
(
Text
(
favorites
[
index
][
'subtitle'
]),
color:
index
%
2
==
0
?
Colors
.
red
[
500
]
:
Colors
.
red
[
400
],
Text
(
favorites
[
index
][
'author'
]),
child:
Text
(
favorites
[
index
][
'title'
]),
Text
(
favorites
[
index
][
'published'
]),
),
Text
(
favorites
[
index
][
'publisher'
]),
Container
(
Text
(
favorites
[
index
][
'description'
]),
color:
index
%
2
==
0
?
Colors
.
red
[
500
]
:
Colors
.
red
[
400
],
Text
(
favorites
[
index
][
'website'
]),
child:
Text
(
favorites
[
index
][
'subtitle'
]),
];
),
Container
(
color:
index
%
2
==
0
?
Colors
.
red
[
500
]
:
Colors
.
red
[
400
],
child:
Text
(
favorites
[
index
][
'author'
]),
),
Container
(
color:
index
%
2
==
0
?
Colors
.
red
[
500
]
:
Colors
.
red
[
400
],
child:
Text
(
favorites
[
index
][
'published'
]),
),
Container
(
color:
index
%
2
==
0
?
Colors
.
red
[
500
]
:
Colors
.
red
[
400
],
child:
Text
(
favorites
[
index
][
'publisher'
]),
),
Container
(
color:
index
%
2
==
0
?
Colors
.
red
[
500
]
:
Colors
.
red
[
400
],
child:
Text
(
favorites
[
index
][
'description'
]),
),
Container
(
color:
index
%
2
==
0
?
Colors
.
red
[
500
]
:
Colors
.
red
[
400
],
child:
Text
(
favorites
[
index
][
'website'
]),
)
)
]
);
}
}
))
))
;
});
});
}
}
}
}
tp1/lib/main.dart
View file @
dc5cd0b9
...
@@ -2,6 +2,8 @@ import 'package:english_words/english_words.dart';
...
@@ -2,6 +2,8 @@ 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
'app_state.dart'
;
void
main
(
)
{
void
main
(
)
{
...
@@ -14,7 +16,7 @@ class MyApp extends StatelessWidget {
...
@@ -14,7 +16,7 @@ class MyApp extends StatelessWidget {
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
ChangeNotifierProvider
(
return
ChangeNotifierProvider
(
create:
(
context
)
=>
My
AppState
(),
create:
(
context
)
=>
AppState
(),
child:
MaterialApp
(
child:
MaterialApp
(
title:
'Namer App'
,
title:
'Namer App'
,
theme:
ThemeData
(
theme:
ThemeData
(
...
@@ -116,7 +118,7 @@ class _MyHomePageState extends State<MyHomePage> {
...
@@ -116,7 +118,7 @@ class _MyHomePageState extends State<MyHomePage> {
class
GeneratorPage
extends
StatelessWidget
{
class
GeneratorPage
extends
StatelessWidget
{
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
var
appState
=
context
.
watch
<
My
AppState
>();
var
appState
=
context
.
watch
<
AppState
>();
var
pair
=
appState
.
current
;
var
pair
=
appState
.
current
;
IconData
icon
;
IconData
icon
;
...
@@ -186,27 +188,3 @@ class BigCard extends StatelessWidget {
...
@@ -186,27 +188,3 @@ class BigCard extends StatelessWidget {
);
);
}
}
}
}
class
FavoritePage
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
var
appState
=
context
.
watch
<
MyAppState
>();
var
favorites
=
appState
.
favorites
;
return
Scaffold
(
body:
Column
(
children:
[
Text
(
'Favorites'
),
for
(
var
fav
in
favorites
)
Text
(
fav
.
asLowerCase
),
],)
);
}
}
\ No newline at end of file
tp1/pubspec.lock
View file @
dc5cd0b9
...
@@ -79,26 +79,26 @@ packages:
...
@@ -79,26 +79,26 @@ packages:
dependency: transitive
dependency: transitive
description:
description:
name: leak_tracker
name: leak_tracker
sha256:
cdd14e3836065a1f6302a236ec8b5f700695c803c57ae11a1c84df31e6bcf831
sha256:
"7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
url: "https://pub.dev"
url: "https://pub.dev"
source: hosted
source: hosted
version: "10.0.
3
"
version: "10.0.
4
"
leak_tracker_flutter_testing:
leak_tracker_flutter_testing:
dependency: transitive
dependency: transitive
description:
description:
name: leak_tracker_flutter_testing
name: leak_tracker_flutter_testing
sha256: "
9b2ef90589911d665277464e0482b209d39882dffaaf4ef69a3561a3354b2ebc
"
sha256: "
06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8
"
url: "https://pub.dev"
url: "https://pub.dev"
source: hosted
source: hosted
version: "3.0.
2
"
version: "3.0.
3
"
leak_tracker_testing:
leak_tracker_testing:
dependency: transitive
dependency: transitive
description:
description:
name: leak_tracker_testing
name: leak_tracker_testing
sha256:
fd3cd66cb2bcd7b50dcd3b413af49d78051f809c8b3f6e047962765c15a0d23d
sha256:
"6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
url: "https://pub.dev"
url: "https://pub.dev"
source: hosted
source: hosted
version: "3.0.
0
"
version: "3.0.
1
"
lints:
lints:
dependency: transitive
dependency: transitive
description:
description:
...
@@ -127,10 +127,10 @@ packages:
...
@@ -127,10 +127,10 @@ packages:
dependency: transitive
dependency: transitive
description:
description:
name: meta
name: meta
sha256:
d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
sha256:
"7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
url: "https://pub.dev"
url: "https://pub.dev"
source: hosted
source: hosted
version: "1.1
1
.0"
version: "1.1
2
.0"
nested:
nested:
dependency: transitive
dependency: transitive
description:
description:
...
...
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