-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.dart
104 lines (99 loc) · 3.17 KB
/
main.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import 'package:flutter/material.dart';
import 'dart:html' as html;
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _url = 'https://flutter.dev';
double _width = 0.5;
double _height = 0.5;
@override
Widget build(BuildContext context) {
final screen = html.window.screen;
final height = screen.height * _height;
final width = screen.width * _width;
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: Container(
width: 300,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ListTile(
title: TextFormField(
initialValue: _url,
onChanged: (val) {
_url = val;
},
decoration: InputDecoration(
labelText: "URL",
),
),
),
ListTile(
title: Text('Width % = ${width.toStringAsFixed(1)}'),
subtitle: Slider(
value: _width,
onChanged: (val) {
if (mounted)
setState(() {
_width = val;
});
},
),
),
ListTile(
title: Text('Height % = ${height.toStringAsFixed(1)}'),
subtitle: Slider(
value: _height,
onChanged: (val) {
if (mounted)
setState(() {
_height = val;
});
},
),
),
RaisedButton.icon(
icon: Icon(Icons.desktop_windows),
label: Text('Create Window'),
onPressed: () {
_createWindow(_url, Size(height, width));
},
),
],
),
),
),
),
);
}
void _createWindow(String url, Size size, {Offset offset, String name = ''}) {
final screen = html.window.screen;
final height = size.height;
final width = size.width;
final sb = StringBuffer();
final top =
offset?.dy ?? (screen.height != null ? (screen.height - height) / 2 : 0);
final left =
offset?.dx ?? (screen.width != null ? (screen.width - width) / 2 : 0);
sb.write("height=");
sb.write(height);
sb.write(",width=");
sb.write(width);
sb.write(",top=");
sb.write(top);
sb.write(",left=");
sb.write(left);
sb.write(
",scrollbars=yes,resizable=yes,toolbar=no,status=no,menu=no, directories=no,titlebar=no,location=no,addressbar=no");
final settings = sb.toString();
html.window.open(url, name, settings);
}
}