Skip to content

Commit cb50726

Browse files
committed
-
1 parent bd4e527 commit cb50726

File tree

7 files changed

+65
-25
lines changed

7 files changed

+65
-25
lines changed

pkgs/example/lib/app/app.dart

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import 'package:flutter/material.dart';
55

66
class MyApp extends StatelessWidget {
77
const MyApp({super.key});
8+
static const _appTitle = 'GenUI Example';
89

910
@override
1011
Widget build(BuildContext context) {
1112
return MaterialApp(
12-
title: 'GenUI Example',
13+
debugShowCheckedModeBanner: false,
14+
title: _appTitle,
1315
theme: ThemeData(
14-
colorScheme: ColorScheme.fromSeed(seedColor: Colors.white),
16+
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
1517
),
1618
home: const _MyHomePage(),
1719
);
@@ -32,9 +34,27 @@ class _MyHomePageState extends State<_MyHomePage> {
3234

3335
@override
3436
Widget build(BuildContext context) {
35-
return GenUi.invitation(
36-
initialPrompt: 'Invite user to create a vacation travel itinerary.',
37-
controller: _controller,
37+
return Scaffold(
38+
appBar: AppBar(
39+
leading: Icon(Icons.menu),
40+
title: Row(
41+
children: const <Widget>[
42+
Icon(Icons.chat_bubble_outline),
43+
SizedBox(width: 8.0), // Add spacing between icon and text
44+
Text('Chat'),
45+
],
46+
),
47+
actions: [Icon(Icons.person_outline), SizedBox(width: 8.0)],
48+
),
49+
body: Padding(
50+
padding: const EdgeInsets.all(16.0),
51+
child: Center(
52+
child: GenUi.invitation(
53+
initialPrompt: 'Invite user to create a vacation travel itinerary.',
54+
controller: _controller,
55+
),
56+
),
57+
),
3858
);
3959
}
4060

pkgs/example/lib/sdk/agent/agent.dart

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ class GenUiAgent {
1111

1212
Future<WidgetBuilder> request(Input input, GenUiController controller) async {
1313
// Simulate network delay
14-
await Future.delayed(const Duration(milliseconds: 1500));
15-
switch (input.runtimeType) {
16-
case InvitationInput _:
17-
return (_) =>
18-
Invitation(data: fakeInvitationData, controller: controller);
19-
default:
20-
throw Exception('Unsupported input type: ${input.runtimeType}');
21-
}
14+
await Future.delayed(const Duration(milliseconds: 1000));
15+
return switch (input) {
16+
InvitationInput _ => (_) => Invitation(
17+
data: fakeInvitationData,
18+
controller: controller,
19+
),
20+
_ => throw UnimplementedError(
21+
'GenUiAgent does not support input of type ${input.runtimeType}',
22+
),
23+
};
2224
}
2325
}

pkgs/example/lib/sdk/agent/fake_output.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:example/sdk/catalog/text_intro.dart';
44

55
final fakeInvitationData = InvitationData(
66
textIntroData: TextIntroData(
7-
h1: 'Hello, Ryan,',
7+
h1: 'Hello Ryan,',
88
h2: 'Welcome to traveling with Compass',
99
intro:
1010
'Explore our promotions below or let me know '

pkgs/example/lib/sdk/agent/widget.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ class _GenUiState extends State<GenUi> {
2121
WidgetBuilder? _widgetBuilder;
2222

2323
@override
24-
void initState() async {
24+
void initState() {
2525
super.initState();
26+
_initialize();
27+
}
28+
29+
Future<void> _initialize() async {
2630
final builder = await GenUiAgent.instance.request(
2731
InvitationInput(widget.initialPrompt),
2832
widget.controller,
2933
);
30-
3134
setState(() => _widgetBuilder = builder);
3235
}
3336

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
import 'package:flutter/material.dart';
22

33
class ChatBox extends StatelessWidget {
4-
const ChatBox({super.key});
4+
ChatBox({super.key});
5+
final _controller = TextEditingController();
56

67
@override
78
Widget build(BuildContext context) {
8-
return const Placeholder();
9+
return TextField(
10+
controller: _controller,
11+
decoration: InputDecoration(
12+
hintText: 'Ask me anything',
13+
border: const OutlineInputBorder(
14+
borderRadius: BorderRadius.all(Radius.circular(25.0)),
15+
),
16+
17+
suffixIcon: IconButton(icon: const Icon(Icons.send), onPressed: () {}),
18+
),
19+
maxLines: null, // Allows for multi-line input
20+
keyboardType: TextInputType.multiline,
21+
textInputAction: TextInputAction.send,
22+
onSubmitted: (String value) => _submit(),
23+
);
924
}
25+
26+
void _submit() {}
1027
}

pkgs/example/lib/sdk/catalog/invitation.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ class Invitation extends StatelessWidget {
1717
crossAxisAlignment: CrossAxisAlignment.start,
1818
children: [
1919
TextIntro(data: data.textIntroData),
20+
SizedBox(height: 16.0),
2021
Text(data.exploreTitle, style: GenUiTextStyles.h2(context)),
2122
Carousel(data: CarouselData(items: data.exploreItems)),
22-
Padding(padding: const EdgeInsets.only(top: 16.0), child: ChatBox()),
23+
SizedBox(height: 16.0),
24+
ChatBox(),
2325
],
2426
);
2527
}

pkgs/example/lib/sdk/catalog/shared/text_styles.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,9 @@ abstract class GenUiTextStyles {
77

88
static TextStyle h1(BuildContext context) => normal(
99
context,
10-
).copyWith(fontSize: 46.0, fontWeight: FontWeight.w900, inherit: true);
10+
).copyWith(fontSize: 36.0, fontWeight: FontWeight.w900, inherit: true);
1111

1212
static TextStyle h2(BuildContext context) => normal(
1313
context,
14-
).copyWith(fontSize: 26.0, fontWeight: FontWeight.w200, inherit: true);
15-
16-
static TextStyle h3(BuildContext context) => normal(
17-
context,
18-
).copyWith(fontSize: 24.0, fontWeight: FontWeight.w200, inherit: true);
14+
).copyWith(fontSize: 22.0, fontWeight: FontWeight.w200, inherit: true);
1915
}

0 commit comments

Comments
 (0)