Skip to content

Commit eaf0e5a

Browse files
Add rebuild script for tfrs-flutter (#2294)
1 parent 315d1ab commit eaf0e5a

File tree

494 files changed

+5993
-2853
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

494 files changed

+5993
-2853
lines changed

tfrs-flutter/codelab_rebuild.yaml

Lines changed: 323 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,323 @@
1+
name: tfrs-flutter rebuild script
2+
steps:
3+
- name: step0
4+
steps:
5+
- name: Remove generated code
6+
rmdir: step0/frontend
7+
- name: Create project
8+
flutter: create frontend --project-name=recommend_products
9+
- name: Replace README
10+
path: frontend/README.md
11+
replace-contents: |
12+
# Flutter frontend of a recommendation engine demo
13+
14+
This Flutter app is the frontend to consume the data feed from a backend recommender.
15+
- name: Strip DEVELOPMENT_TEAM
16+
strip-lines-containing: DEVELOPMENT_TEAM =
17+
path: frontend/ios/Runner.xcodeproj/project.pbxproj
18+
- name: Add deps
19+
path: frontend
20+
flutter: pub add http
21+
- name: Configure analysis_options.yaml
22+
path: frontend/analysis_options.yaml
23+
replace-contents: |
24+
include: ../../../analysis_options.yaml
25+
26+
analyzer:
27+
errors:
28+
unused_import: ignore
29+
unused_field: ignore
30+
unused_local_variable: ignore
31+
- name: Replace lib/main.dart
32+
path: frontend/lib/main.dart
33+
replace-contents: |
34+
import 'dart:io' show Platform;
35+
36+
import 'package:flutter/foundation.dart' show kIsWeb;
37+
import 'package:flutter/material.dart';
38+
39+
void main() => runApp(const RecommenderDemo());
40+
41+
class RecommenderDemo extends StatefulWidget {
42+
const RecommenderDemo({super.key});
43+
44+
@override
45+
State<RecommenderDemo> createState() => _RecommenderDemoState();
46+
}
47+
48+
class _RecommenderDemoState extends State<RecommenderDemo> {
49+
late List<String> _movieList;
50+
final TextEditingController _userIDController = TextEditingController();
51+
late String _server;
52+
late Future<List<String>> _futureRecommendations;
53+
54+
@override
55+
void initState() {
56+
super.initState();
57+
_futureRecommendations = Future<List<String>>.value([]);
58+
}
59+
60+
Future<List<String>> recommend() async {
61+
if (!kIsWeb && Platform.isAndroid) {
62+
// For Android emulator
63+
_server = '10.0.2.2';
64+
} else {
65+
// For iOS emulator, desktop and web platforms
66+
_server = '127.0.0.1';
67+
}
68+
69+
//TODO: add code to send request to the recommendation engine backend
70+
71+
return [];
72+
}
73+
74+
@override
75+
Widget build(BuildContext context) {
76+
const title = 'Flutter Movie Recommendation Demo';
77+
78+
return MaterialApp(
79+
title: title,
80+
theme: ThemeData.light(),
81+
home: Scaffold(
82+
appBar: AppBar(title: const Text(title)),
83+
body: Center(
84+
child: Container(
85+
padding: const EdgeInsets.fromLTRB(20, 0, 20, 0),
86+
child: Column(
87+
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
88+
children: [
89+
Row(
90+
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
91+
children: [
92+
Expanded(
93+
child: TextField(
94+
controller: _userIDController,
95+
decoration: const InputDecoration(
96+
border: UnderlineInputBorder(),
97+
hintText: 'Enter a user ID here',
98+
),
99+
),
100+
),
101+
Container(
102+
margin: const EdgeInsets.only(left: 10.0),
103+
child: FilledButton(
104+
style: FilledButton.styleFrom(
105+
textStyle: const TextStyle(fontSize: 15),
106+
),
107+
onPressed: () {
108+
setState(() {
109+
_futureRecommendations = recommend();
110+
});
111+
},
112+
child: const Text('Recommend'),
113+
),
114+
),
115+
],
116+
),
117+
FutureBuilder<List<String>>(
118+
future: _futureRecommendations,
119+
builder: (context, snapshot) {
120+
if (snapshot.hasData) {
121+
_movieList = snapshot.data!;
122+
return ListView.builder(
123+
scrollDirection: Axis.vertical,
124+
shrinkWrap: true,
125+
itemCount: _movieList.length,
126+
itemBuilder: (context, index) {
127+
return ListTile(
128+
leading:
129+
_movieList.isEmpty ? null : const FlutterLogo(),
130+
title: Text(_movieList[index]),
131+
);
132+
},
133+
);
134+
} else if (snapshot.hasError) {
135+
return Text('${snapshot.error}');
136+
}
137+
// By default, show a loading spinner.
138+
return const CircularProgressIndicator();
139+
},
140+
),
141+
],
142+
),
143+
),
144+
),
145+
),
146+
);
147+
}
148+
}
149+
- name: Replace test/widget_test.dart
150+
path: frontend/test/widget_test.dart
151+
replace-contents: |
152+
// This is a basic Flutter widget test.
153+
//
154+
// To perform an interaction with a widget in your test, use the WidgetTester
155+
// utility that Flutter provides. For example, you can send tap and scroll
156+
// gestures. You can also use WidgetTester to find child widgets in the widget
157+
// tree, read text, and verify that the values of widget properties are correct.
158+
159+
import 'package:flutter_test/flutter_test.dart';
160+
161+
import 'package:recommend_products/main.dart';
162+
163+
void main() {
164+
testWidgets('Smoke test', (tester) async {
165+
// Build our app and trigger a frame.
166+
await tester.pumpWidget(const RecommenderDemo());
167+
168+
// Verify that the widgets are there
169+
expect(find.text('Recommend'), findsOneWidget);
170+
});
171+
}
172+
- name: Patch macos/Runner/DebugProfile.entitlements
173+
path: frontend/macos/Runner/DebugProfile.entitlements
174+
patch-u: |
175+
--- b/frontend/finished/macos/Runner/DebugProfile.entitlements
176+
+++ a/frontend/finished/macos/Runner/DebugProfile.entitlements
177+
@@ -8,5 +8,7 @@
178+
<true/>
179+
<key>com.apple.security.network.server</key>
180+
<true/>
181+
+ <key>com.apple.security.network.client</key>
182+
+ <true/>
183+
</dict>
184+
</plist>
185+
- name: Patch macos/Runner/Release.entitlements
186+
path: frontend/macos/Runner/Release.entitlements
187+
patch-u: |
188+
--- b/frontend/finished/macos/Runner/Release.entitlements
189+
+++ a/frontend/finished/macos/Runner/Release.entitlements
190+
@@ -4,5 +4,7 @@
191+
<dict>
192+
<key>com.apple.security.app-sandbox</key>
193+
<true/>
194+
+ <key>com.apple.security.network.client</key>
195+
+ <true/>
196+
</dict>
197+
</plist>
198+
- name: Copy step0
199+
copydir:
200+
from: frontend
201+
to: step0/frontend
202+
- name: Flutter clean
203+
path: step0/frontend
204+
flutter: clean
205+
- name: step1
206+
steps:
207+
- name: Remove generated code
208+
rmdir: step1/frontend
209+
- name: Copy step1
210+
copydir:
211+
from: frontend
212+
to: step1/frontend
213+
- name: Flutter clean
214+
path: step1/frontend
215+
flutter: clean
216+
- name: step2
217+
steps:
218+
- name: Remove generated code
219+
rmdir: step2/frontend
220+
- name: Copy step2
221+
copydir:
222+
from: frontend
223+
to: step2/frontend
224+
- name: Flutter clean
225+
path: step2/frontend
226+
flutter: clean
227+
- name: step3
228+
steps:
229+
- name: Remove generated code
230+
rmdir: step3/frontend
231+
- name: Copy step3
232+
copydir:
233+
from: frontend
234+
to: step3/frontend
235+
- name: Flutter clean
236+
path: step3/frontend
237+
flutter: clean
238+
- name: step4
239+
steps:
240+
- name: Remove generated code
241+
rmdir: step4/frontend
242+
- name: Patch analysis_options.yaml
243+
path: frontend/analysis_options.yaml
244+
patch-u: |
245+
--- b/tfagents-flutter/finished/frontend/analysis_options.yaml
246+
+++ a/tfagents-flutter/finished/frontend/analysis_options.yaml
247+
@@ -1,7 +1 @@
248+
include: ../../../analysis_options.yaml
249+
-
250+
-analyzer:
251+
- errors:
252+
- unused_import: ignore
253+
- unused_field: ignore
254+
- unused_local_variable: ignore
255+
- name: Patch lib/main.dart
256+
path: frontend/lib/main.dart
257+
patch-u: |
258+
--- b/tfrs-flutter/step4/frontend/lib/main.dart
259+
+++ a/tfrs-flutter/step4/frontend/lib/main.dart
260+
@@ -1,7 +1,9 @@
261+
+import 'dart:convert';
262+
import 'dart:io' show Platform;
263+
264+
import 'package:flutter/foundation.dart' show kIsWeb;
265+
import 'package:flutter/material.dart';
266+
+import 'package:http/http.dart' as http;
267+
268+
void main() => runApp(const RecommenderDemo());
269+
270+
@@ -32,10 +34,19 @@ class _RecommenderDemoState extends State<RecommenderDemo> {
271+
// For iOS emulator, desktop and web platforms
272+
_server = '127.0.0.1';
273+
}
274+
+ final response = await http.post(
275+
+ Uri.parse('http://$_server:5000/recommend'),
276+
+ headers: <String, String>{'Content-Type': 'application/json'},
277+
+ body: jsonEncode(<String, String>{'user_id': _userIDController.text}),
278+
+ );
279+
280+
- //TODO: add code to send request to the recommendation engine backend
281+
-
282+
- return [];
283+
+ if (response.statusCode == 200) {
284+
+ return List<String>.from(
285+
+ jsonDecode(response.body)['movies'] as Iterable<dynamic>,
286+
+ );
287+
+ } else {
288+
+ throw Exception('Error response');
289+
+ }
290+
}
291+
292+
@override
293+
- name: Copy step4
294+
copydir:
295+
from: frontend
296+
to: step4/frontend
297+
- name: Flutter clean
298+
path: step4/frontend
299+
flutter: clean
300+
- name: step5
301+
steps:
302+
- name: Remove generated code
303+
rmdir: step5/frontend
304+
- name: Copy step5
305+
copydir:
306+
from: frontend
307+
to: step5/frontend
308+
- name: Flutter clean
309+
path: step5/frontend
310+
flutter: clean
311+
- name: finished
312+
steps:
313+
- name: Remove generated code
314+
rmdir: finished/frontend
315+
- name: Copy finished
316+
copydir:
317+
from: frontend
318+
to: finished/frontend
319+
- name: Flutter clean
320+
path: finished/frontend
321+
flutter: clean
322+
- name: Cleanup
323+
rmdir: frontend

tfrs-flutter/finished/frontend/.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
*.swp
66
.DS_Store
77
.atom/
8+
.build/
89
.buildlog/
910
.history
1011
.svn/
12+
.swiftpm/
13+
migrate_working_dir/
1114

1215
# IntelliJ related
1316
*.iml
@@ -26,14 +29,10 @@
2629
.dart_tool/
2730
.flutter-plugins
2831
.flutter-plugins-dependencies
29-
.packages
3032
.pub-cache/
3133
.pub/
3234
/build/
3335

34-
# Web related
35-
lib/generated_plugin_registrant.dart
36-
3736
# Symbolication related
3837
app.*.symbols
3938

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Flutter frontend of a recommendation engine demo
22

3-
This Flutter app is the frontend to consume the data feed from a backend recommender.
3+
This Flutter app is the frontend to consume the data feed from a backend recommender.
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
11
include: ../../../analysis_options.yaml
2-
3-
analyzer:
4-
5-
linter:
6-
rules:

tfrs-flutter/finished/frontend/android/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ gradle-wrapper.jar
55
/gradlew.bat
66
/local.properties
77
GeneratedPluginRegistrant.java
8+
.cxx/
89

910
# Remember to never publicly share your keystore.
10-
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11+
# See https://flutter.dev/to/reference-keystore
1112
key.properties
1213
**/*.keystore
1314
**/*.jks

0 commit comments

Comments
 (0)