hwrtc_plugin 0.0.1 hwrtc_plugin: ^0.0.1 copied to clipboard
hwrtc project.
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:test_plugin/test_plugin.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
String btnActionTitle = 'HWRTC';
var testPlugin;
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
// platformVersion =
// await TestPlugin.platformVersion ?? 'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
// _platformVersion = platformVersion;
});
}
@override
Widget build(BuildContext context) {
TestView testView = TestView(
onCreated: onTestViewCreated,
);
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('HWRTC Plugin'),
),
body: Column(
children: [
Container(
height: 300,
width: double.infinity,
child: testView,
),
Expanded(
child: SingleChildScrollView(
physics: const BouncingScrollPhysics(),
child: Column(
children: [
SizedBox(
width: double.infinity,
height: 600,
child: DefaultTabController(
length: choices.length,
child: Scaffold(
backgroundColor: Colors.black,
appBar: TabBar(
unselectedLabelColor: Colors.grey,
labelColor: Colors.blueAccent,
isScrollable: true,
tabs: choices.map((Choice choice) {
return Tab(
text: choice.title,
icon: Icon(choice.icon),
);
}).toList(),
),
body: TabBarView(
children: choices.map((Choice choice) {
return Padding(
padding: const EdgeInsets.all(16.0),
child: ChoiceCard(
key: const Key('1'), choice: choice),
);
}).toList(),
),
),
),
),
Container(
margin: EdgeInsets.only(top: 10, bottom: 10),
child: FloatingActionButton(
child: Text('HWRTC'), onPressed: onNativeMethon),
)
],
),
)),
],
),
),
);
}
void onTestViewCreated(testPlugin) {
this.testPlugin = testPlugin;
}
void nativeCallback(str) {
this.btnActionTitle = str;
}
void onNativeMethon() {
this.testPlugin.changeNativeTitle('Flutter 调用原生成功了');
}
}
class Choice {
const Choice({ required this.title, required this.icon });
final String title;
final IconData icon;
}
const List<Choice> choices = [
Choice(title: 'CAR', icon: Icons.directions_car),
Choice(title: 'BICYCLE', icon: Icons.directions_bike),
Choice(title: 'BOAT', icon: Icons.directions_boat),
Choice(title: 'BUS', icon: Icons.directions_bus),
Choice(title: 'TRAIN', icon: Icons.directions_railway),
Choice(title: 'WALK', icon: Icons.directions_walk),
];
class ChoiceCard extends StatelessWidget {
const ChoiceCard({ required Key key, required this.choice }) : super(key: key);
final Choice choice;
@override
Widget build(BuildContext context) {
final TextStyle textStyle = Theme.of(context).textTheme.bodyText1!;
return Card(
color: Colors.white,
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Icon(choice.icon, size: 32.0 , color: textStyle.color),
Text(choice.title, style: textStyle),
],
),
),
);
}
}