mirror of
https://github.com/flutter/samples.git
synced 2025-11-10 23:08:59 +00:00
[platform_channels] adds BasicMessageChannel Demo (#484)
This commit is contained in:
86
platform_channels/lib/src/add_pet_details.dart
Normal file
86
platform_channels/lib/src/add_pet_details.dart
Normal file
@@ -0,0 +1,86 @@
|
||||
// Copyright 2020 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:platform_channels/src/pet_list_message_channel.dart';
|
||||
|
||||
/// Demonstrates how to use [BasicMessageChannel] to send a message to platform.
|
||||
///
|
||||
/// The widget uses [TextField] and [RadioListTile] to take the [PetDetails.breed] and
|
||||
/// [PetDetails.petType] from the user respectively.
|
||||
class AddPetDetails extends StatefulWidget {
|
||||
@override
|
||||
_AddPetDetailsState createState() => _AddPetDetailsState();
|
||||
}
|
||||
|
||||
class _AddPetDetailsState extends State<AddPetDetails> {
|
||||
final breedTextController = TextEditingController();
|
||||
String petType = 'Dog';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Add Pet Details'),
|
||||
actions: <Widget>[
|
||||
IconButton(
|
||||
icon: Icon(Icons.add),
|
||||
onPressed: () {
|
||||
PetListMessageChannel.addPetDetails(
|
||||
PetDetails(
|
||||
petType: petType,
|
||||
breed: breedTextController.text,
|
||||
),
|
||||
);
|
||||
|
||||
Navigator.pop(context);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
TextField(
|
||||
controller: breedTextController,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
filled: true,
|
||||
hintText: 'Breed of pet',
|
||||
labelText: 'Breed',
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
RadioListTile<String>(
|
||||
title: const Text('Dog'),
|
||||
value: 'Dog',
|
||||
groupValue: petType,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
petType = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
RadioListTile<String>(
|
||||
title: const Text('Cat'),
|
||||
value: 'Cat',
|
||||
groupValue: petType,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
petType = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user