mirror of
https://github.com/flutter/samples.git
synced 2025-11-10 06:48:26 +00:00
[platform_channels] adds implementation of BasicMessageChannel for iOS (#610)
This commit is contained in:
@@ -25,6 +25,11 @@ class PlatformChannelSample extends StatelessWidget {
|
||||
'/addPetDetails': (context) => AddPetDetails(),
|
||||
},
|
||||
title: 'Platform Channel Sample',
|
||||
theme: ThemeData(
|
||||
snackBarTheme: SnackBarThemeData(
|
||||
backgroundColor: Colors.blue[500],
|
||||
),
|
||||
),
|
||||
home: HomePage(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ class PetListScreen extends StatefulWidget {
|
||||
|
||||
class _PetListScreenState extends State<PetListScreen> {
|
||||
PetListModel petListModel;
|
||||
final scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -23,9 +24,17 @@ class _PetListScreenState extends State<PetListScreen> {
|
||||
// to PetModel.
|
||||
BasicMessageChannel('stringCodecDemo', StringCodec())
|
||||
.setMessageHandler((message) async {
|
||||
setState(() {
|
||||
petListModel = PetListModel.fromJson(message);
|
||||
});
|
||||
if (message == null) {
|
||||
scaffoldKey.currentState.showSnackBar(
|
||||
SnackBar(
|
||||
content:
|
||||
const Text('An error occurred while adding pet details.')),
|
||||
);
|
||||
} else {
|
||||
setState(() {
|
||||
petListModel = PetListModel.fromJson(message);
|
||||
});
|
||||
}
|
||||
return;
|
||||
});
|
||||
}
|
||||
@@ -33,6 +42,7 @@ class _PetListScreenState extends State<PetListScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
key: scaffoldKey,
|
||||
appBar: AppBar(
|
||||
title: Text('Pet List'),
|
||||
),
|
||||
@@ -84,7 +94,6 @@ class BuildPetList extends StatelessWidget {
|
||||
|
||||
void showSnackBar(String message, BuildContext context) {
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
content: Text(message),
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user