1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 13:58:47 +00:00
Files
samples/experimental/federated_plugin/federated_plugin/example/lib/main.dart
Miguel Beltran bce29a0ff2 Fix master channel build (#1900)
- Fixes #1899 - Don't use BuildContext in async.
- Disabled build script for `next-gen-ui-demo` for master channel
because dependency gap does not compile.
- Improve use BuildContext in `place_tracker`, added checks to verify
that the context is still mounted, and avoid passing BuildContext as
parameter.

## Pre-launch Checklist

- [ ] I read the [Flutter Style Guide] _recently_, and have followed its
advice.
- [ ] I signed the [CLA].
- [ ] I read the [Contributors Guide].
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-devrel
channel on [Discord].

<!-- Links -->
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[CLA]: https://cla.developers.google.com/
[Discord]: https://github.com/flutter/flutter/wiki/Chat
[Contributors Guide]:
https://github.com/flutter/samples/blob/main/CONTRIBUTING.md
2023-06-20 21:29:56 +10:00

80 lines
2.2 KiB
Dart

// 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:federated_plugin/federated_plugin.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.light(useMaterial3: true),
home: const HomePage(),
);
}
}
/// Demonstrates how to use the getBatteryLevel method from federated_plugin to retrieve
/// current battery level of device.
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int? batteryLevel;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Federated Plugin Demo'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
batteryLevel == null
? const SizedBox.shrink()
: Text(
'Battery Level: $batteryLevel',
style: Theme.of(context).textTheme.headlineSmall,
),
const SizedBox(height: 16),
FilledButton(
onPressed: () async {
try {
final result = await getBatteryLevel();
setState(() {
batteryLevel = result;
});
} catch (error) {
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
backgroundColor: Theme.of(context).primaryColor,
content: Text(
(error as dynamic).message as String,
),
),
);
}
},
child: const Text('Get Battery Level'),
),
],
),
),
);
}
}