|
| 1 | +import 'package:flutter/cupertino.dart'; |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | +import 'package:bitsdojo_window/bitsdojo_window.dart'; |
| 4 | +import 'package:flutter_bloc/flutter_bloc.dart'; |
| 5 | +import 'package:todo_client/state/mainStore.dart'; |
| 6 | +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; |
| 7 | + |
| 8 | +void main() { |
| 9 | + runApp(const MyApp()); |
| 10 | + doWhenWindowReady(() { |
| 11 | + final win = appWindow; |
| 12 | + const initialSize = Size(1050, 700); |
| 13 | + win.minSize = initialSize; |
| 14 | + win.size = initialSize; |
| 15 | + win.alignment = Alignment.center; |
| 16 | + win.title = "Custom window with Flutter"; |
| 17 | + win.show(); |
| 18 | + }); |
| 19 | +} |
| 20 | + |
| 21 | +const borderColor = Color(0xFF805306); |
| 22 | + |
| 23 | +class MyApp extends StatelessWidget { |
| 24 | + const MyApp({Key? key}) : super(key: key); |
| 25 | + @override |
| 26 | + Widget build(BuildContext context) { |
| 27 | + return BlocProvider( |
| 28 | + create: (_) => MainStore(), |
| 29 | + child: BlocBuilder<MainStore, MainState>(builder: (context, state) { |
| 30 | + return MaterialApp( |
| 31 | + debugShowCheckedModeBanner: false, |
| 32 | + theme: state.currentTheme, |
| 33 | + home: Scaffold( |
| 34 | + body: WindowBorder( |
| 35 | + color: borderColor, |
| 36 | + width: 1, |
| 37 | + child: Column( |
| 38 | + children: [ |
| 39 | + const TopBar(), |
| 40 | + Text(state.theme.toString()), |
| 41 | + ElevatedButton( |
| 42 | + onPressed: () { |
| 43 | + context |
| 44 | + .read<MainStore>() |
| 45 | + .changeTheme(BaseThemeMode.blue); |
| 46 | + }, |
| 47 | + child: const Text('change theme')), |
| 48 | + IconButton( |
| 49 | + padding: const EdgeInsets.all(0), |
| 50 | + hoverColor: Colors.transparent, |
| 51 | + splashColor: Colors.transparent, |
| 52 | + icon: const Icon( |
| 53 | + Icons.arrow_back_ios, |
| 54 | + size: 15, |
| 55 | + ), |
| 56 | + onPressed: () {}, |
| 57 | + ), |
| 58 | + ], |
| 59 | + ), |
| 60 | + ), |
| 61 | + ), |
| 62 | + ); |
| 63 | + }), |
| 64 | + ); |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +class TopBar extends StatelessWidget { |
| 69 | + const TopBar({Key? key}) : super(key: key); |
| 70 | + @override |
| 71 | + Widget build(BuildContext context) { |
| 72 | + return LayoutBuilder( |
| 73 | + builder: ((BuildContext context, BoxConstraints boxConstraints) { |
| 74 | + return Container( |
| 75 | + width: boxConstraints.maxWidth, |
| 76 | + height: 60, |
| 77 | + color: Theme.of(context).primaryColor, |
| 78 | + child: MoveWindow( |
| 79 | + child: Row( |
| 80 | + mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 81 | + children: [ |
| 82 | + DefaultTextStyle( |
| 83 | + style: const TextStyle(color: Colors.white), |
| 84 | + child: Padding( |
| 85 | + padding: const EdgeInsets.symmetric(horizontal: 20), |
| 86 | + child: Row( |
| 87 | + crossAxisAlignment: CrossAxisAlignment.center, |
| 88 | + children: [ |
| 89 | + const Text( |
| 90 | + 'todoList', |
| 91 | + style: TextStyle(fontSize: 18), |
| 92 | + ), |
| 93 | + const SizedBox( |
| 94 | + width: 100, |
| 95 | + ), |
| 96 | + CupertinoButton( |
| 97 | + child: const Icon(Icons.arrow_back_ios, |
| 98 | + size: 15, color: Colors.white), |
| 99 | + onPressed: () {}), |
| 100 | + CupertinoButton( |
| 101 | + padding: const EdgeInsets.all(0), |
| 102 | + child: const Icon(Icons.arrow_forward_ios, |
| 103 | + size: 15, color: Colors.white), |
| 104 | + onPressed: () {}) |
| 105 | + ], |
| 106 | + ), |
| 107 | + )), |
| 108 | + Row( |
| 109 | + crossAxisAlignment: CrossAxisAlignment.center, |
| 110 | + children: [ |
| 111 | + MouseRegion( |
| 112 | + cursor: SystemMouseCursors.click, |
| 113 | + child: CupertinoButton( |
| 114 | + padding: const EdgeInsets.all(0), |
| 115 | + child: const FaIcon( |
| 116 | + FontAwesomeIcons.shirt, |
| 117 | + color: Colors.white, |
| 118 | + size: 14, |
| 119 | + ), |
| 120 | + onPressed: () {}), |
| 121 | + ), |
| 122 | + const WindowButtons(), |
| 123 | + ], |
| 124 | + ) |
| 125 | + ], |
| 126 | + )), |
| 127 | + ); |
| 128 | + })); |
| 129 | + } |
| 130 | +} |
| 131 | + |
| 132 | +final buttonColors = WindowButtonColors( |
| 133 | + iconNormal: Colors.white, |
| 134 | + mouseOver: Colors.transparent, |
| 135 | + mouseDown: Colors.transparent, |
| 136 | +); |
| 137 | + |
| 138 | +class WindowButtons extends StatefulWidget { |
| 139 | + const WindowButtons({Key? key}) : super(key: key); |
| 140 | + |
| 141 | + @override |
| 142 | + _WindowButtonsState createState() => _WindowButtonsState(); |
| 143 | +} |
| 144 | + |
| 145 | +class _WindowButtonsState extends State<WindowButtons> { |
| 146 | + void maximizeOrRestore() { |
| 147 | + setState(() { |
| 148 | + appWindow.maximizeOrRestore(); |
| 149 | + }); |
| 150 | + } |
| 151 | + |
| 152 | + @override |
| 153 | + Widget build(BuildContext context) { |
| 154 | + return Row( |
| 155 | + crossAxisAlignment: CrossAxisAlignment.center, |
| 156 | + children: [ |
| 157 | + MinimizeWindowButton(colors: buttonColors), |
| 158 | + appWindow.isMaximized |
| 159 | + ? RestoreWindowButton( |
| 160 | + colors: buttonColors, |
| 161 | + onPressed: maximizeOrRestore, |
| 162 | + ) |
| 163 | + : MaximizeWindowButton( |
| 164 | + colors: buttonColors, |
| 165 | + onPressed: maximizeOrRestore, |
| 166 | + ), |
| 167 | + CloseWindowButton(colors: buttonColors), |
| 168 | + ], |
| 169 | + ); |
| 170 | + } |
| 171 | +} |
0 commit comments