2025-04-04 14:41:13 +08:00
|
|
|
import 'package:appflowy_ui/appflowy_ui.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2025-05-27 17:31:16 +08:00
|
|
|
import 'src/avatar/avatar_page.dart';
|
2025-04-15 17:02:08 +08:00
|
|
|
import 'src/buttons/buttons_page.dart';
|
2025-05-27 17:31:16 +08:00
|
|
|
import 'src/dropdown_menu/dropdown_menu_page.dart';
|
|
|
|
import 'src/menu/menu_page.dart';
|
2025-04-15 17:02:08 +08:00
|
|
|
import 'src/modal/modal_page.dart';
|
|
|
|
import 'src/textfield/textfield_page.dart';
|
|
|
|
|
2025-04-04 14:41:13 +08:00
|
|
|
enum ThemeMode {
|
|
|
|
light,
|
|
|
|
dark,
|
|
|
|
}
|
|
|
|
|
|
|
|
final themeMode = ValueNotifier(ThemeMode.light);
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
runApp(
|
|
|
|
const MyApp(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
const MyApp({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ValueListenableBuilder(
|
|
|
|
valueListenable: themeMode,
|
|
|
|
builder: (context, themeMode, child) {
|
2025-04-18 14:14:38 +08:00
|
|
|
final themeBuilder = AppFlowyDefaultTheme();
|
2025-04-14 13:03:49 +08:00
|
|
|
final themeData =
|
|
|
|
themeMode == ThemeMode.light ? ThemeData.light() : ThemeData.dark();
|
2025-04-18 14:14:38 +08:00
|
|
|
|
|
|
|
return AnimatedAppFlowyTheme(
|
2025-04-04 14:41:13 +08:00
|
|
|
data: themeMode == ThemeMode.light
|
2025-04-18 14:14:38 +08:00
|
|
|
? themeBuilder.light()
|
|
|
|
: themeBuilder.dark(),
|
2025-04-04 14:41:13 +08:00
|
|
|
child: MaterialApp(
|
|
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
title: 'AppFlowy UI Example',
|
2025-04-18 14:14:38 +08:00
|
|
|
theme: themeData.copyWith(
|
|
|
|
visualDensity: VisualDensity.standard,
|
|
|
|
),
|
2025-04-04 14:41:13 +08:00
|
|
|
home: const MyHomePage(
|
|
|
|
title: 'AppFlowy UI',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyHomePage extends StatefulWidget {
|
|
|
|
const MyHomePage({
|
|
|
|
super.key,
|
|
|
|
required this.title,
|
|
|
|
});
|
|
|
|
|
|
|
|
final String title;
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<MyHomePage> createState() => _MyHomePageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
|
|
|
final tabs = [
|
|
|
|
Tab(text: 'Button'),
|
|
|
|
Tab(text: 'TextField'),
|
2025-04-15 17:02:08 +08:00
|
|
|
Tab(text: 'Modal'),
|
2025-05-14 19:19:43 +08:00
|
|
|
Tab(text: 'Avatar'),
|
|
|
|
Tab(text: 'Menu'),
|
2025-05-27 17:31:16 +08:00
|
|
|
Tab(text: 'Dropdown Menu'),
|
2025-04-04 14:41:13 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final theme = AppFlowyTheme.of(context);
|
|
|
|
return DefaultTabController(
|
|
|
|
length: tabs.length,
|
|
|
|
child: Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
|
|
|
title: Text(
|
|
|
|
widget.title,
|
|
|
|
style: theme.textStyle.title.enhanced(
|
|
|
|
color: theme.textColorScheme.primary,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(
|
2025-04-17 13:54:28 +08:00
|
|
|
Theme.of(context).brightness == Brightness.light
|
2025-04-04 14:41:13 +08:00
|
|
|
? Icons.dark_mode
|
|
|
|
: Icons.light_mode,
|
|
|
|
),
|
|
|
|
onPressed: _toggleTheme,
|
|
|
|
tooltip: 'Toggle theme',
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
body: TabBarView(
|
|
|
|
children: [
|
|
|
|
ButtonsPage(),
|
|
|
|
TextFieldPage(),
|
2025-04-15 17:02:08 +08:00
|
|
|
ModalPage(),
|
2025-05-14 19:19:43 +08:00
|
|
|
AvatarPage(),
|
|
|
|
MenuPage(),
|
2025-05-27 17:31:16 +08:00
|
|
|
DropdownMenuPage(),
|
2025-04-04 14:41:13 +08:00
|
|
|
],
|
|
|
|
),
|
|
|
|
bottomNavigationBar: TabBar(
|
|
|
|
tabs: tabs,
|
|
|
|
),
|
|
|
|
floatingActionButton: null,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _toggleTheme() {
|
|
|
|
themeMode.value =
|
|
|
|
themeMode.value == ThemeMode.light ? ThemeMode.dark : ThemeMode.light;
|
|
|
|
}
|
|
|
|
}
|