import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:screen_brightness/screen_brightness.dart';
import 'package:mini_tias/screens/capture_screen.dart';
import 'package:mini_tias/screens/gallery_screen.dart';
/// BottomNavigationBar で撮影画面と一覧画面を切り替えるホーム画面.
///
/// UI 全体を 180° 回転して表示する(端末を逆さに置いて使用するため).
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
int _currentIndex = 0;
double _brightness = 0.8;
static const _screens = [CaptureScreen(), GalleryScreen()];
@override
void initState() {
super.initState();
_setBrightness(_brightness);
}
@override
void dispose() {
ScreenBrightness.instance.resetApplicationScreenBrightness();
super.dispose();
}
Future<void> _setBrightness(double value) async {
await ScreenBrightness.instance.setApplicationScreenBrightness(value);
}
@override
Widget build(BuildContext context) {
final screenHeight = MediaQuery.of(context).size.height;
final attachmentPadding = screenHeight / 3;
return Transform.rotate(
angle: math.pi,
child: Scaffold(
body: Padding(
padding: EdgeInsets.only(bottom: attachmentPadding),
child: _screens[_currentIndex],
),
bottomNavigationBar: Padding(
padding: EdgeInsets.only(bottom: attachmentPadding),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Row(
children: [
const Icon(Icons.brightness_low, size: 20),
Expanded(
child: Slider(
value: _brightness,
onChanged: (value) {
setState(() => _brightness = value);
_setBrightness(value);
},
),
),
const Icon(Icons.brightness_high, size: 20),
],
),
),
BottomNavigationBar(
currentIndex: _currentIndex,
onTap: (index) => setState(() => _currentIndex = index),
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.camera_alt),
label: '撮影',
),
BottomNavigationBarItem(
icon: Icon(Icons.photo_library),
label: '一覧',
),
],
),
],
),
),
),
);
}
}