-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathdark_mode.dart
75 lines (64 loc) · 2.13 KB
/
dark_mode.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2024 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart';
import 'package:google_generative_ai/google_generative_ai.dart';
import '../dark_style.dart';
import '../gemini_api_key.dart';
void main() => runApp(const App());
class App extends StatelessWidget {
static const title = 'Example: Dark Mode';
static final themeMode = ValueNotifier(ThemeMode.dark);
const App({super.key});
@override
Widget build(BuildContext context) => ValueListenableBuilder<ThemeMode>(
valueListenable: themeMode,
builder:
(BuildContext context, ThemeMode mode, Widget? child) => MaterialApp(
title: title,
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
themeMode: mode,
home: ChatPage(),
debugShowCheckedModeBanner: false,
),
);
}
class ChatPage extends StatefulWidget {
const ChatPage({super.key});
@override
State<ChatPage> createState() => _ChatPageState();
}
class _ChatPageState extends State<ChatPage> {
final _provider = GeminiProvider(
model: GenerativeModel(model: 'gemini-2.0-flash', apiKey: geminiApiKey),
);
final _lightStyle = LlmChatViewStyle.defaultStyle();
final _darkStyle = darkChatViewStyle();
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: const Text(App.title),
actions: [
IconButton(
onPressed:
() =>
App.themeMode.value =
App.themeMode.value == ThemeMode.light
? ThemeMode.dark
: ThemeMode.light,
tooltip:
App.themeMode.value == ThemeMode.light
? 'Dark Mode'
: 'Light Mode',
icon: const Icon(Icons.brightness_4_outlined),
),
],
),
body: LlmChatView(
provider: _provider,
style: App.themeMode.value == ThemeMode.dark ? _darkStyle : _lightStyle,
),
);
}