Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
MyFlutter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
정 원빈
MyFlutter
Commits
053771bf
Commit
053771bf
authored
1 month ago
by
wonbin
Browse files
Options
Downloads
Patches
Plain Diff
backend_integration
parent
d18dda1f
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/main.dart
+64
-11
64 additions, 11 deletions
lib/main.dart
pubspec.lock
+32
-0
32 additions, 0 deletions
pubspec.lock
pubspec.yaml
+1
-0
1 addition, 0 deletions
pubspec.yaml
with
97 additions
and
11 deletions
lib/main.dart
+
64
−
11
View file @
053771bf
import
'dart:convert'
;
import
'package:english_words/english_words.dart'
;
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
'package:http/http.dart'
as
http
;
void
main
()
{
void
main
()
{
runApp
(
MyApp
());
runApp
(
ChangeNotifierProvider
(
create:
(
context
)
=
>
MyAppState
(),
child:
const
MyApp
(),
),
);
}
}
class
MyApp
extends
StatelessWidget
{
class
MyApp
extends
StatelessWidget
{
...
@@ -11,15 +19,26 @@ class MyApp extends StatelessWidget {
...
@@ -11,15 +19,26 @@ class MyApp extends StatelessWidget {
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
ChangeNotifierProvider
(
var
appstate
=
context
.
watch
<
MyAppState
>();
create:
(
context
)
=
>
MyAppState
(),
return
MaterialApp
(
child:
MaterialApp
(
title:
'Namer App'
,
title:
'Namer App'
,
theme:
ThemeData
(
theme:
ThemeData
(
useMaterial3:
true
,
useMaterial3:
true
,
colorScheme:
ColorScheme
.
fromSeed
(
seedColor:
Colors
.
deepOrange
),
colorScheme:
ColorScheme
.
fromSeed
(
seedColor:
Colors
.
deepOrange
),
),
),
home:
MyHomePage
(),
home:
FutureBuilder
<
List
<
WordPair
>>(
future:
appstate
.
futureFavorites
,
builder:
(
context
,
snapshot
)
{
if
(
snapshot
.
connectionState
==
ConnectionState
.
waiting
)
{
return
const
Center
(
child:
CircularProgressIndicator
());
}
else
if
(
snapshot
.
hasError
)
{
return
Center
(
child:
Text
(
'Error :
${snapshot.error}
'
),);
}
else
if
(
snapshot
.
hasData
)
{
return
MyHomePage
();
}
else
{
return
Center
(
child:
Text
(
'No Favorites yet'
));
}
}
),
),
);
);
}
}
...
@@ -32,15 +51,49 @@ class MyAppState extends ChangeNotifier {
...
@@ -32,15 +51,49 @@ class MyAppState extends ChangeNotifier {
notifyListeners
();
notifyListeners
();
}
}
var
favorites
=
<
WordPair
>[];
var
favorites
=
<
WordPair
>[];
late
Future
<
List
<
WordPair
>>
futureFavorites
;
MyAppState
()
{
futureFavorites
=
fetchFavorites
();
}
void
toggleFavorite
()
{
Future
<
List
<
WordPair
>>
fetchFavorites
()
async
{
final
response
=
await
http
.
get
(
Uri
.
parse
(
'https://wonbin3977.web.ajousw.kr/likes'
));
List
<
WordPair
>
list
=
[];
var
jsonData
=
jsonDecode
(
response
.
body
);
for
(
Map
<
String
,
dynamic
>
obj
in
jsonData
)
{
List
<
String
>
res
=
obj
[
"id"
]
.
split
(
'_'
);
list
.
add
(
WordPair
(
res
[
0
],
res
[
1
]));
}
favorites
=
[..
.
list
];
notifyListeners
();
return
list
;
}
Future
<
void
>
toggleFavorite
()
async
{
var
uri
=
"https:wonbin3977.web.ajousw.kr/likes/
${current.first}
_
${current.second}
"
;
if
(
favorites
.
contains
(
current
))
{
if
(
favorites
.
contains
(
current
))
{
final
http
.
Response
resp
=
await
http
.
delete
(
Uri
.
parse
(
uri
));
if
(
resp
.
statusCode
!=
200
)
{
return
;
}
favorites
.
remove
(
current
);
favorites
.
remove
(
current
);
favorites
=
[..
.
favorites
];
}
else
{
}
else
{
favorites
.
add
(
current
);
final
http
.
Response
resp
=
await
http
.
post
(
Uri
.
parse
(
uri
),
);
if
(
resp
.
statusCode
!=
200
)
{
return
;
}
}
favorites
=
[..
.
favorites
,
current
];
}
print
(
favorites
);
notifyListeners
();
notifyListeners
();
}
}
}
}
// ...
// ...
...
...
This diff is collapsed.
Click to expand it.
pubspec.lock
+
32
−
0
View file @
053771bf
...
@@ -75,6 +75,22 @@ packages:
...
@@ -75,6 +75,22 @@ packages:
description: flutter
description: flutter
source: sdk
source: sdk
version: "0.0.0"
version: "0.0.0"
http:
dependency: "direct main"
description:
name: http
sha256: "2c11f3f94c687ee9bad77c171151672986360b2b001d109814ee7140b2cf261b"
url: "https://pub.dev"
source: hosted
version: "1.4.0"
http_parser:
dependency: transitive
description:
name: http_parser
sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571"
url: "https://pub.dev"
source: hosted
version: "4.1.2"
leak_tracker:
leak_tracker:
dependency: transitive
dependency: transitive
description:
description:
...
@@ -208,6 +224,14 @@ packages:
...
@@ -208,6 +224,14 @@ packages:
url: "https://pub.dev"
url: "https://pub.dev"
source: hosted
source: hosted
version: "0.7.4"
version: "0.7.4"
typed_data:
dependency: transitive
description:
name: typed_data
sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006
url: "https://pub.dev"
source: hosted
version: "1.4.0"
vector_math:
vector_math:
dependency: transitive
dependency: transitive
description:
description:
...
@@ -224,6 +248,14 @@ packages:
...
@@ -224,6 +248,14 @@ packages:
url: "https://pub.dev"
url: "https://pub.dev"
source: hosted
source: hosted
version: "14.3.1"
version: "14.3.1"
web:
dependency: transitive
description:
name: web
sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a"
url: "https://pub.dev"
source: hosted
version: "1.1.1"
sdks:
sdks:
dart: ">=3.7.0-0 <4.0.0"
dart: ">=3.7.0-0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
flutter: ">=3.18.0-18.0.pre.54"
This diff is collapsed.
Click to expand it.
pubspec.yaml
+
1
−
0
View file @
053771bf
...
@@ -14,6 +14,7 @@ dependencies:
...
@@ -14,6 +14,7 @@ dependencies:
english_words
:
^4.0.0
english_words
:
^4.0.0
provider
:
^6.0.0
provider
:
^6.0.0
http
:
^1.4.0
dev_dependencies
:
dev_dependencies
:
flutter_test
:
flutter_test
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment