connect ui
This commit is contained in:
parent
e4681f7d9a
commit
da7a71cd81
@ -17,9 +17,16 @@ class HexColor extends Color {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MyTheme {
|
||||||
|
static const Color grayBg = Color(0xFFEEEEEE);
|
||||||
|
static const Color white = Color(0xFFFFFFFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef F1 = void Function(Pointer<Utf8>);
|
||||||
|
|
||||||
// https://juejin.im/post/6844903864852807694
|
// https://juejin.im/post/6844903864852807694
|
||||||
class FfiModel with ChangeNotifier {
|
class FfiModel with ChangeNotifier {
|
||||||
var _connectRemote;
|
F1 _connectRemote;
|
||||||
|
|
||||||
FfiModel() {
|
FfiModel() {
|
||||||
initialzeFFI();
|
initialzeFFI();
|
||||||
@ -39,8 +46,8 @@ class FfiModel with ChangeNotifier {
|
|||||||
: DynamicLibrary.process();
|
: DynamicLibrary.process();
|
||||||
final initialize = dylib.lookupFunction<Void Function(Pointer<Utf8>),
|
final initialize = dylib.lookupFunction<Void Function(Pointer<Utf8>),
|
||||||
void Function(Pointer<Utf8>)>('initialize');
|
void Function(Pointer<Utf8>)>('initialize');
|
||||||
_connectRemote = dylib.lookupFunction<Void Function(Pointer<Utf8>),
|
_connectRemote = dylib
|
||||||
void Function(Pointer<Utf8>)>('connect_remote');
|
.lookupFunction<Void Function(Pointer<Utf8>), F1>('connect_remote');
|
||||||
final dir = (await getApplicationDocumentsDirectory()).path;
|
final dir = (await getApplicationDocumentsDirectory()).path;
|
||||||
initialize(Utf8.toUtf8(dir));
|
initialize(Utf8.toUtf8(dir));
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
import 'common.dart';
|
import 'common.dart';
|
||||||
|
|
||||||
class HomePage extends StatefulWidget {
|
class HomePage extends StatefulWidget {
|
||||||
@ -11,112 +12,106 @@ class HomePage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _HomePageState extends State<HomePage> {
|
class _HomePageState extends State<HomePage> {
|
||||||
int _counter = 0;
|
final idController = TextEditingController();
|
||||||
|
FfiModel ffi;
|
||||||
void _incrementCounter() {
|
|
||||||
setState(() {
|
|
||||||
_counter++;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
ffi = Provider.of<FfiModel>(context);
|
||||||
|
|
||||||
// This method is rerun every time setState is called
|
// This method is rerun every time setState is called
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(widget.title),
|
title: Text(widget.title),
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: <Widget>[
|
|
||||||
Text(
|
|
||||||
'You have pushed the button this many times:',
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
'$_counter',
|
|
||||||
style: Theme.of(context).textTheme.headline4,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
body: Container(
|
||||||
floatingActionButton: FloatingActionButton(
|
child: Column(
|
||||||
onPressed: _incrementCounter,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
tooltip: 'Increment',
|
mainAxisSize: MainAxisSize.max,
|
||||||
child: Icon(Icons.add),
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
),
|
children: <Widget>[
|
||||||
);
|
getSearchBarUI(),
|
||||||
|
Expanded(child: Container())
|
||||||
|
]),
|
||||||
|
color: MyTheme.grayBg,
|
||||||
|
padding: const EdgeInsets.fromLTRB(16.0, 0.0, 16.0, 0.0),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
void onConnect() {
|
||||||
|
ffi.connect(idController.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget getSearchBarUI() {
|
Widget getSearchBarUI() {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.only(top: 8.0, left: 18),
|
padding: const EdgeInsets.only(top: 8.0),
|
||||||
child: Row(
|
child: Container(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
height: 84,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
child: Padding(
|
||||||
children: <Widget>[
|
padding: const EdgeInsets.only(top: 8, bottom: 8),
|
||||||
Container(
|
child: Container(
|
||||||
width: MediaQuery.of(context).size.width * 0.75,
|
decoration: BoxDecoration(
|
||||||
height: 64,
|
color: MyTheme.white,
|
||||||
child: Padding(
|
borderRadius: const BorderRadius.only(
|
||||||
padding: const EdgeInsets.only(top: 8, bottom: 8),
|
bottomRight: Radius.circular(13.0),
|
||||||
child: Container(
|
bottomLeft: Radius.circular(13.0),
|
||||||
decoration: BoxDecoration(
|
topLeft: Radius.circular(13.0),
|
||||||
color: HexColor('#F8FAFB'),
|
topRight: Radius.circular(13.0),
|
||||||
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: <Widget>[
|
|
||||||
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')),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
child: Row(
|
||||||
|
children: <Widget>[
|
||||||
|
Expanded(
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.only(left: 16, right: 16),
|
||||||
|
child: TextFormField(
|
||||||
|
style: TextStyle(
|
||||||
|
fontFamily: 'WorkSans',
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
fontSize: 30,
|
||||||
|
color: Color(0xFF00B6F0),
|
||||||
|
),
|
||||||
|
keyboardType: TextInputType.text,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: 'Remote ID',
|
||||||
|
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'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
autofocus: false,
|
||||||
|
controller: idController,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
width: 60,
|
||||||
|
height: 60,
|
||||||
|
child: IconButton(
|
||||||
|
icon: Icon(Icons.arrow_forward,
|
||||||
|
color: HexColor('#B9BABC'), size: 45),
|
||||||
|
onPressed: onConnect,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const Expanded(
|
),
|
||||||
child: SizedBox(),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
idController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,10 @@ import 'common.dart';
|
|||||||
import 'home_page.dart';
|
import 'home_page.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(_App());
|
runApp(App());
|
||||||
}
|
}
|
||||||
|
|
||||||
class _App extends StatelessWidget {
|
class App extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var ffi = FfiModel();
|
var ffi = FfiModel();
|
||||||
|
@ -13,7 +13,7 @@ import 'package:flutter_hbb/main.dart';
|
|||||||
void main() {
|
void main() {
|
||||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||||
// Build our app and trigger a frame.
|
// Build our app and trigger a frame.
|
||||||
await tester.pumpWidget(MyApp());
|
await tester.pumpWidget(App());
|
||||||
|
|
||||||
// Verify that our counter starts at 0.
|
// Verify that our counter starts at 0.
|
||||||
expect(find.text('0'), findsOneWidget);
|
expect(find.text('0'), findsOneWidget);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user