Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // main.dart
- import 'package:fluent_ui/fluent_ui.dart';
- import 'package:flutter_rss/router/router.dart';
- import 'package:go_router/go_router.dart';
- import 'package:window_manager_plus/window_manager_plus.dart';
- void main() async {
- WidgetsFlutterBinding.ensureInitialized();
- await WindowManagerPlus.ensureInitialized(0);
- WindowOptions windowOptions = const WindowOptions(
- size: Size(800, 600),
- center: true,
- title: "Flutter RSS",
- skipTaskbar: false,
- titleBarStyle: TitleBarStyle.normal,
- backgroundColor: Colors.successPrimaryColor,
- );
- WindowManagerPlus.current.waitUntilReadyToShow(windowOptions, () async {
- await WindowManagerPlus.current.show();
- await WindowManagerPlus.current.focus();
- });
- runApp(const MyApp());
- }
- class MyApp extends StatelessWidget {
- const MyApp({super.key});
- @override
- Widget build(BuildContext context) {
- return FluentApp.router(
- routerConfig: router,
- title: 'Flutter RSS',
- themeMode: ThemeMode.system,
- theme: FluentThemeData(
- brightness: Brightness.light,
- accentColor: Colors.blue,
- ),
- darkTheme: FluentThemeData(
- brightness: Brightness.dark,
- accentColor: Colors.orange,
- ),
- );
- }
- }
- class HomePage extends StatefulWidget {
- const HomePage({super.key, required this.title, required this.child});
- final String title;
- final Widget child;
- @override
- State<StatefulWidget> createState() => _HomePageState();
- }
- class _HomePageState extends State<HomePage> with WindowListener {
- int index = 0;
- @override
- Widget build(BuildContext context) {
- return NavigationView(
- paneBodyBuilder: (item, body) {
- return widget.child;
- },
- pane: NavigationPane(
- displayMode: PaneDisplayMode.open,
- selected: index,
- onChanged: (i) {
- setState(() {
- index = i;
- });
- },
- items: [
- PaneItem(
- icon: const Icon(FluentIcons.add),
- title: Text("Home"),
- infoBadge: InfoBadge(source: Text("9+")),
- body: SizedBox.shrink(),
- onTap: () => context.go("/"),
- ),
- ],
- footerItems: [
- PaneItem(
- icon: const Icon(FluentIcons.settings),
- key: const ValueKey("/settings"),
- title: Text("Settings"),
- body: SizedBox.shrink(),
- onTap: () => context.go("/settings"),
- ),
- ],
- ),
- );
- }
- }
- //home_view.dart
- import 'package:fluent_ui/fluent_ui.dart';
- class HomeView extends StatelessWidget {
- const HomeView({super.key});
- @override
- Widget build(BuildContext context) {
- return ScaffoldPage(content: Center(child: Text("This is the home page.")));
- }
- }
- //settings_view.dart
- import 'package:fluent_ui/fluent_ui.dart';
- class SettingsView extends StatelessWidget {
- const SettingsView({super.key});
- @override
- Widget build(BuildContext context) {
- return ScaffoldPage(
- content: Column(
- spacing: 10,
- children: [
- DecoratedBox(
- decoration: BoxDecoration(
- border: BoxBorder.all(),
- color: Colors.grey,
- ),
- child: Column(
- children: [
- ListTile(
- title: Text("Option 1"),
- subtitle: Text("This is the first setting"),
- trailing: ToggleSwitch(checked: false, onChanged: (b) {}),
- ),
- ListTile(
- title: Text("Option 2"),
- subtitle: Text("This is the second setting"),
- trailing: ToggleSwitch(checked: false, onChanged: (b) {}),
- ),
- ],
- ),
- ),
- DecoratedBox(
- decoration: BoxDecoration(
- border: BoxBorder.all(),
- color: Colors.grey,
- ),
- child: Column(
- children: [
- ListTile(
- title: Text("Option 3"),
- subtitle: Text("This is the third setting"),
- trailing: ToggleSwitch(checked: false, onChanged: (b) {}),
- ),
- ListTile(
- title: Text("Option 4"),
- subtitle: Text("This is the fourth setting"),
- trailing: ToggleSwitch(checked: false, onChanged: (b) {}),
- ),
- ],
- ),
- ),
- ],
- ),
- );
- }
- }
- //router.dart
- import 'package:fluent_ui/fluent_ui.dart';
- import 'package:flutter_rss/main.dart';
- import 'package:flutter_rss/views/home_view.dart';
- import 'package:flutter_rss/views/settings_view.dart';
- import 'package:go_router/go_router.dart';
- final router = GoRouter(
- routes: [
- ShellRoute(
- builder: (contest, state, child) {
- return HomePage(title: 'Flutter RSS', child: child);
- },
- routes: [
- GoRoute(
- path: "/",
- pageBuilder: (context, state) {
- return CustomTransitionPage(
- key: state.pageKey,
- child: HomeView(key: Key('/')),
- transitionsBuilder:
- (context, animation, secondaryAnimation, child) {
- return HorizontalSlidePageTransition(
- animation: animation,
- fromLeft: false,
- child: child,
- );
- },
- );
- },
- ),
- GoRoute(
- path: "/settings",
- pageBuilder: (context, state) {
- return CustomTransitionPage(
- key: state.pageKey,
- opaque: false,
- child: SettingsView(key: Key('settings')),
- transitionDuration: Duration(milliseconds: 200),
- transitionsBuilder:
- (context, animation, secondaryAnimation, child) {
- return HorizontalSlidePageTransition(
- animation: animation,
- fromLeft: true,
- child: child,
- );
- },
- );
- },
- ),
- ],
- ),
- ],
- );
Advertisement
Add Comment
Please, Sign In to add comment