device_orientation_for_x 0.0.2 device_orientation_for_x: ^0.0.2 copied to clipboard
Check how the device is rotated even if system rotation is disabled and make sure widgets are always pointing down.
import 'package:device_orientation_for_x/device_orientation.dart';
import 'package:device_orientation_for_x/widgets/always_down.dart';
import 'package:device_orientation_for_x/widgets/animated_always_down.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() => boot();
Future<void> boot() async {
WidgetsFlutterBinding.ensureInitialized();
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => MaterialApp(
title: 'Absolute device rotation demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const ExamplePage(),
);
}
class ExamplePage extends StatelessWidget {
const ExamplePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: const Text('Down pointers example'),
systemOverlayStyle: SystemUiOverlayStyle.light,
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
StreamBuilder<DeviceOrientation>(
stream: deviceOrientation$,
initialData: deviceOrientation,
builder: (context, snapshot) => Text(snapshot.data!.name),
),
const Center(
child: Icon(Icons.smartphone, size: 64),
),
const Center(
child: Icon(Icons.arrow_downward, size: 64),
),
const Center(
child: AlwaysDown(
child: Icon(Icons.arrow_downward, size: 64),
),
),
const Center(
child: AnimatedAlwaysDown(
child: Icon(Icons.arrow_downward, size: 64),
),
),
],
),
);
}