diff --git a/flutter_hbb/lib/common.dart b/flutter_hbb/lib/common.dart new file mode 100644 index 000000000..d424e7e85 --- /dev/null +++ b/flutter_hbb/lib/common.dart @@ -0,0 +1,48 @@ +import 'package:flutter/material.dart'; +import 'package:ffi/ffi.dart'; +import 'package:path_provider/path_provider.dart'; +import 'dart:io'; +import 'dart:ffi'; +import 'dart:async'; + +class HexColor extends Color { + HexColor(final String hexColor) : super(_getColorFromHex(hexColor)); + + static int _getColorFromHex(String hexColor) { + hexColor = hexColor.toUpperCase().replaceAll('#', ''); + if (hexColor.length == 6) { + hexColor = 'FF' + hexColor; + } + return int.parse(hexColor, radix: 16); + } +} + +// https://juejin.im/post/6844903864852807694 +class FfiModel with ChangeNotifier { + var _connectRemote; + + FfiModel() { + initialzeFFI(); + } + + void addRemote() { + notifyListeners(); + } + + void connect(String id) { + _connectRemote(Utf8.toUtf8(id)); + } + + Future initialzeFFI() async { + final dylib = Platform.isAndroid + ? DynamicLibrary.open('librustdesk.so') + : DynamicLibrary.process(); + final initialize = dylib.lookupFunction), + void Function(Pointer)>('initialize'); + _connectRemote = dylib.lookupFunction), + void Function(Pointer)>('connect_remote'); + final dir = (await getApplicationDocumentsDirectory()).path; + initialize(Utf8.toUtf8(dir)); + notifyListeners(); + } +} diff --git a/flutter_hbb/lib/home_page.dart b/flutter_hbb/lib/home_page.dart new file mode 100644 index 000000000..c96f307f0 --- /dev/null +++ b/flutter_hbb/lib/home_page.dart @@ -0,0 +1,122 @@ +import 'package:flutter/material.dart'; +import 'common.dart'; + +class HomePage extends StatefulWidget { + HomePage({Key key, this.title}) : super(key: key); + + final String title; + + @override + _HomePageState createState() => _HomePageState(); +} + +class _HomePageState extends State { + int _counter = 0; + + void _incrementCounter() { + setState(() { + _counter++; + }); + } + + @override + Widget build(BuildContext context) { + // This method is rerun every time setState is called + return Scaffold( + appBar: AppBar( + title: Text(widget.title), + ), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + 'You have pushed the button this many times:', + ), + Text( + '$_counter', + style: Theme.of(context).textTheme.headline4, + ), + ], + ), + ), + floatingActionButton: FloatingActionButton( + onPressed: _incrementCounter, + tooltip: 'Increment', + child: Icon(Icons.add), + ), + ); + } + + Widget getSearchBarUI() { + return Padding( + padding: const EdgeInsets.only(top: 8.0, left: 18), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + width: MediaQuery.of(context).size.width * 0.75, + height: 64, + child: Padding( + padding: const EdgeInsets.only(top: 8, bottom: 8), + child: Container( + decoration: BoxDecoration( + color: HexColor('#F8FAFB'), + borderRadius: const BorderRadius.only( + bottomRight: Radius.circular(13.0), + bottomLeft: Radius.circular(13.0), + topLeft: Radius.circular(13.0), + topRight: Radius.circular(13.0), + ), + ), + child: Row( + children: [ + Expanded( + child: Container( + padding: const EdgeInsets.only(left: 16, right: 16), + child: TextFormField( + style: TextStyle( + fontFamily: 'WorkSans', + fontWeight: FontWeight.bold, + fontSize: 16, + color: Color(0xFF00B6F0), + ), + keyboardType: TextInputType.text, + decoration: InputDecoration( + labelText: 'Search for course', + border: InputBorder.none, + helperStyle: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 16, + color: HexColor('#B9BABC'), + ), + labelStyle: TextStyle( + fontWeight: FontWeight.w600, + fontSize: 16, + letterSpacing: 0.2, + color: HexColor('#B9BABC'), + ), + ), + onEditingComplete: () {}, + ), + ), + ), + SizedBox( + width: 60, + height: 60, + child: Icon(Icons.search, color: HexColor('#B9BABC')), + ) + ], + ), + ), + ), + ), + const Expanded( + child: SizedBox(), + ) + ], + ), + ); + } +} diff --git a/flutter_hbb/lib/main.dart b/flutter_hbb/lib/main.dart index 708c2926f..959de8fbe 100644 --- a/flutter_hbb/lib/main.dart +++ b/flutter_hbb/lib/main.dart @@ -1,132 +1,25 @@ -import 'package:ffi/ffi.dart'; import 'package:flutter/material.dart'; -import 'package:path_provider/path_provider.dart'; -import 'dart:io'; -import 'dart:ffi'; -import 'dart:async'; +import 'package:provider/provider.dart'; +import 'common.dart'; +import 'home_page.dart'; void main() { - // final connect_remote = dylib.lookupFunction), void Function(Pointer)>('connect_remote'); - // connect_remote(Utf8.toUtf8('test')); - runApp(MyApp()); + runApp(_App()); } -Future initialzeFFI() async { - final dylib = Platform.isAndroid ? DynamicLibrary.open('librustdesk.so') : DynamicLibrary.process(); - String dir = (await getApplicationDocumentsDirectory()).path; - final initialize = dylib.lookupFunction), void Function(Pointer)>('initialize'); - initialize(Utf8.toUtf8(dir)); -} - -class MyApp extends StatelessWidget { - // This widget is the root of your application. +class _App extends StatelessWidget { @override Widget build(BuildContext context) { - initialzeFFI(); - return MaterialApp( - title: 'Flutter Demo', - theme: ThemeData( - // This is the theme of your application. - // - // Try running your application with "flutter run". You'll see the - // application has a blue toolbar. Then, without quitting the app, try - // changing the primarySwatch below to Colors.green and then invoke - // "hot reload" (press "r" in the console where you ran "flutter run", - // or simply save your changes to "hot reload" in a Flutter IDE). - // Notice that the counter didn't reset back to zero; the application - // is not restarted. - primarySwatch: Colors.blue, - // This makes the visual density adapt to the platform that you run - // the app on. For desktop platforms, the controls will be smaller and - // closer together (more dense) than on mobile platforms. - visualDensity: VisualDensity.adaptivePlatformDensity, - ), - home: MyHomePage(title: 'Flutter Demo Home Page'), - ); - } -} - -class MyHomePage extends StatefulWidget { - MyHomePage({Key key, this.title}) : super(key: key); - - // This widget is the home page of your application. It is stateful, meaning - // that it has a State object (defined below) that contains fields that affect - // how it looks. - - // This class is the configuration for the state. It holds the values (in this - // case the title) provided by the parent (in this case the App widget) and - // used by the build method of the State. Fields in a Widget subclass are - // always marked "final". - - final String title; - - @override - _MyHomePageState createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State { - int _counter = 0; - - void _incrementCounter() { - setState(() { - // This call to setState tells the Flutter framework that something has - // changed in this State, which causes it to rerun the build method below - // so that the display can reflect the updated values. If we changed - // _counter without calling setState(), then the build method would not be - // called again, and so nothing would appear to happen. - _counter++; - }); - } - - @override - Widget build(BuildContext context) { - // This method is rerun every time setState is called, for instance as done - // by the _incrementCounter method above. - // - // The Flutter framework has been optimized to make rerunning build methods - // fast, so that you can just rebuild anything that needs updating rather - // than having to individually change instances of widgets. - return Scaffold( - appBar: AppBar( - // Here we take the value from the MyHomePage object that was created by - // the App.build method, and use it to set our appbar title. - title: Text(widget.title), - ), - body: Center( - // Center is a layout widget. It takes a single child and positions it - // in the middle of the parent. - child: Column( - // Column is also a layout widget. It takes a list of children and - // arranges them vertically. By default, it sizes itself to fit its - // children horizontally, and tries to be as tall as its parent. - // - // Invoke "debug painting" (press "p" in the console, choose the - // "Toggle Debug Paint" action from the Flutter Inspector in Android - // Studio, or the "Toggle Debug Paint" command in Visual Studio Code) - // to see the wireframe for each widget. - // - // Column has various properties to control how it sizes itself and - // how it positions its children. Here we use mainAxisAlignment to - // center the children vertically; the main axis here is the vertical - // axis because Columns are vertical (the cross axis would be - // horizontal). - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - 'You have pushed the button this many times:', - ), - Text( - '$_counter', - style: Theme.of(context).textTheme.headline4, - ), - ], - ), - ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: Icon(Icons.add), - ), // This trailing comma makes auto-formatting nicer for build methods. - ); + var ffi = FfiModel(); + return ChangeNotifierProvider.value( + value: ffi, + child: MaterialApp( + title: 'RustDesk', + theme: ThemeData( + primarySwatch: Colors.blue, + visualDensity: VisualDensity.adaptivePlatformDensity, + ), + home: HomePage(title: 'RustDesk'), + )); } } diff --git a/flutter_hbb/pubspec.lock b/flutter_hbb/pubspec.lock index 7cb6b1fb0..758ed271c 100644 --- a/flutter_hbb/pubspec.lock +++ b/flutter_hbb/pubspec.lock @@ -102,6 +102,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0-nullsafety.3" + nested: + dependency: transitive + description: + name: nested + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.4" path: dependency: transitive description: @@ -165,6 +172,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.0.13" + provider: + dependency: "direct main" + description: + name: provider + url: "https://pub.dartlang.org" + source: hosted + version: "4.3.2+2" sky_engine: dependency: transitive description: flutter @@ -232,7 +246,7 @@ packages: name: win32 url: "https://pub.dartlang.org" source: hosted - version: "1.7.3" + version: "1.7.4" xdg_directories: dependency: transitive description: @@ -242,4 +256,4 @@ packages: version: "0.1.2" sdks: dart: ">=2.10.0-110 <2.11.0" - flutter: ">=1.12.13+hotfix.5 <2.0.0" + flutter: ">=1.16.0 <2.0.0" diff --git a/flutter_hbb/pubspec.yaml b/flutter_hbb/pubspec.yaml index 921f3fe6d..ad8c52b05 100644 --- a/flutter_hbb/pubspec.yaml +++ b/flutter_hbb/pubspec.yaml @@ -30,6 +30,7 @@ dependencies: cupertino_icons: ^1.0.0 ffi: ^0.1.3 path_provider: ^1.6.24 + provider: ^4.3.2+2 dev_dependencies: flutter_test: