Guest User

Untitled

a guest
Jul 23rd, 2025
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.26 KB | None | 0 0
  1. // main.dart
  2. import 'package:fluent_ui/fluent_ui.dart';
  3. import 'package:flutter_rss/router/router.dart';
  4. import 'package:go_router/go_router.dart';
  5. import 'package:window_manager_plus/window_manager_plus.dart';
  6.  
  7. void main() async {
  8. WidgetsFlutterBinding.ensureInitialized();
  9. await WindowManagerPlus.ensureInitialized(0);
  10. WindowOptions windowOptions = const WindowOptions(
  11. size: Size(800, 600),
  12. center: true,
  13. title: "Flutter RSS",
  14. skipTaskbar: false,
  15. titleBarStyle: TitleBarStyle.normal,
  16. backgroundColor: Colors.successPrimaryColor,
  17. );
  18. WindowManagerPlus.current.waitUntilReadyToShow(windowOptions, () async {
  19. await WindowManagerPlus.current.show();
  20. await WindowManagerPlus.current.focus();
  21. });
  22. runApp(const MyApp());
  23. }
  24.  
  25. class MyApp extends StatelessWidget {
  26. const MyApp({super.key});
  27.  
  28. @override
  29. Widget build(BuildContext context) {
  30. return FluentApp.router(
  31. routerConfig: router,
  32. title: 'Flutter RSS',
  33. themeMode: ThemeMode.system,
  34. theme: FluentThemeData(
  35. brightness: Brightness.light,
  36. accentColor: Colors.blue,
  37. ),
  38. darkTheme: FluentThemeData(
  39. brightness: Brightness.dark,
  40. accentColor: Colors.orange,
  41. ),
  42. );
  43. }
  44. }
  45.  
  46. class HomePage extends StatefulWidget {
  47. const HomePage({super.key, required this.title, required this.child});
  48. final String title;
  49. final Widget child;
  50.  
  51. @override
  52. State<StatefulWidget> createState() => _HomePageState();
  53. }
  54.  
  55. class _HomePageState extends State<HomePage> with WindowListener {
  56. int index = 0;
  57.  
  58. @override
  59. Widget build(BuildContext context) {
  60. return NavigationView(
  61. paneBodyBuilder: (item, body) {
  62. return widget.child;
  63. },
  64. pane: NavigationPane(
  65. displayMode: PaneDisplayMode.open,
  66. selected: index,
  67. onChanged: (i) {
  68. setState(() {
  69. index = i;
  70. });
  71. },
  72. items: [
  73. PaneItem(
  74. icon: const Icon(FluentIcons.add),
  75. title: Text("Home"),
  76. infoBadge: InfoBadge(source: Text("9+")),
  77. body: SizedBox.shrink(),
  78. onTap: () => context.go("/"),
  79. ),
  80. ],
  81. footerItems: [
  82. PaneItem(
  83. icon: const Icon(FluentIcons.settings),
  84. key: const ValueKey("/settings"),
  85. title: Text("Settings"),
  86. body: SizedBox.shrink(),
  87. onTap: () => context.go("/settings"),
  88. ),
  89. ],
  90. ),
  91. );
  92. }
  93. }
  94.  
  95.  
  96. //home_view.dart
  97. import 'package:fluent_ui/fluent_ui.dart';
  98.  
  99. class HomeView extends StatelessWidget {
  100. const HomeView({super.key});
  101.  
  102. @override
  103. Widget build(BuildContext context) {
  104. return ScaffoldPage(content: Center(child: Text("This is the home page.")));
  105. }
  106. }
  107.  
  108.  
  109. //settings_view.dart
  110. import 'package:fluent_ui/fluent_ui.dart';
  111.  
  112. class SettingsView extends StatelessWidget {
  113. const SettingsView({super.key});
  114.  
  115. @override
  116. Widget build(BuildContext context) {
  117. return ScaffoldPage(
  118. content: Column(
  119. spacing: 10,
  120. children: [
  121. DecoratedBox(
  122. decoration: BoxDecoration(
  123. border: BoxBorder.all(),
  124. color: Colors.grey,
  125. ),
  126. child: Column(
  127. children: [
  128. ListTile(
  129. title: Text("Option 1"),
  130. subtitle: Text("This is the first setting"),
  131. trailing: ToggleSwitch(checked: false, onChanged: (b) {}),
  132. ),
  133. ListTile(
  134. title: Text("Option 2"),
  135. subtitle: Text("This is the second setting"),
  136. trailing: ToggleSwitch(checked: false, onChanged: (b) {}),
  137. ),
  138. ],
  139. ),
  140. ),
  141. DecoratedBox(
  142. decoration: BoxDecoration(
  143. border: BoxBorder.all(),
  144. color: Colors.grey,
  145. ),
  146. child: Column(
  147. children: [
  148. ListTile(
  149. title: Text("Option 3"),
  150. subtitle: Text("This is the third setting"),
  151. trailing: ToggleSwitch(checked: false, onChanged: (b) {}),
  152. ),
  153. ListTile(
  154. title: Text("Option 4"),
  155. subtitle: Text("This is the fourth setting"),
  156. trailing: ToggleSwitch(checked: false, onChanged: (b) {}),
  157. ),
  158. ],
  159. ),
  160. ),
  161. ],
  162. ),
  163. );
  164. }
  165. }
  166.  
  167. //router.dart
  168. import 'package:fluent_ui/fluent_ui.dart';
  169. import 'package:flutter_rss/main.dart';
  170. import 'package:flutter_rss/views/home_view.dart';
  171. import 'package:flutter_rss/views/settings_view.dart';
  172. import 'package:go_router/go_router.dart';
  173.  
  174.  
  175. final router = GoRouter(
  176. routes: [
  177. ShellRoute(
  178. builder: (contest, state, child) {
  179. return HomePage(title: 'Flutter RSS', child: child);
  180. },
  181. routes: [
  182. GoRoute(
  183. path: "/",
  184. pageBuilder: (context, state) {
  185. return CustomTransitionPage(
  186. key: state.pageKey,
  187. child: HomeView(key: Key('/')),
  188. transitionsBuilder:
  189. (context, animation, secondaryAnimation, child) {
  190. return HorizontalSlidePageTransition(
  191. animation: animation,
  192. fromLeft: false,
  193. child: child,
  194. );
  195. },
  196. );
  197. },
  198. ),
  199. GoRoute(
  200. path: "/settings",
  201. pageBuilder: (context, state) {
  202. return CustomTransitionPage(
  203. key: state.pageKey,
  204. opaque: false,
  205. child: SettingsView(key: Key('settings')),
  206. transitionDuration: Duration(milliseconds: 200),
  207. transitionsBuilder:
  208. (context, animation, secondaryAnimation, child) {
  209. return HorizontalSlidePageTransition(
  210. animation: animation,
  211. fromLeft: true,
  212. child: child,
  213. );
  214. },
  215. );
  216. },
  217. ),
  218. ],
  219. ),
  220. ],
  221. );
  222.  
Advertisement
Add Comment
Please, Sign In to add comment