@@ -1245,7 +1245,10 @@ class CameraPickerState extends State<CameraPicker>
1245
1245
return const SizedBox .shrink ();
1246
1246
}
1247
1247
Widget backButton = buildBackButton (context);
1248
- Widget flashModeSwitch = buildFlashModeSwitch (context, v);
1248
+ Widget flashModeSwitch = buildFlashModeSwitch (
1249
+ context: context,
1250
+ cameraValue: v,
1251
+ );
1249
1252
if (isCameraRotated && ! enableScaledPreview) {
1250
1253
backButton = RotatedBox (
1251
1254
quarterTurns: cameraQuarterTurns,
@@ -1296,9 +1299,12 @@ class CameraPickerState extends State<CameraPicker>
1296
1299
1297
1300
/// The button to switch flash modes.
1298
1301
/// 切换闪光灯模式的按钮
1299
- Widget buildFlashModeSwitch (BuildContext context, CameraValue value) {
1302
+ Widget buildFlashModeSwitch ({
1303
+ required BuildContext context,
1304
+ required CameraValue cameraValue,
1305
+ }) {
1300
1306
final IconData icon;
1301
- switch (value .flashMode) {
1307
+ switch (cameraValue .flashMode) {
1302
1308
case FlashMode .off:
1303
1309
icon = Icons .flash_off;
1304
1310
break ;
@@ -1313,15 +1319,18 @@ class CameraPickerState extends State<CameraPicker>
1313
1319
break ;
1314
1320
}
1315
1321
return IconButton (
1316
- onPressed: () => switchFlashesMode (value ),
1317
- tooltip: textDelegate.sFlashModeLabel (value .flashMode),
1322
+ onPressed: () => switchFlashesMode (cameraValue ),
1323
+ tooltip: textDelegate.sFlashModeLabel (cameraValue .flashMode),
1318
1324
icon: Icon (icon, size: 24 ),
1319
1325
);
1320
1326
}
1321
1327
1322
1328
/// Text widget for shooting tips.
1323
1329
/// 拍摄的提示文字
1324
- Widget buildCaptureTips (CameraController ? controller) {
1330
+ Widget buildCaptureTips ({
1331
+ required BuildContext context,
1332
+ CameraController ? controller,
1333
+ }) {
1325
1334
return AnimatedOpacity (
1326
1335
duration: recordDetectDuration,
1327
1336
opacity: controller? .value.isRecordingVideo ?? false ? 0 : 1 ,
@@ -1398,7 +1407,10 @@ class CameraPickerState extends State<CameraPicker>
1398
1407
const Spacer (),
1399
1408
Expanded (
1400
1409
child: Center (
1401
- child: buildCaptureButton (context, constraints),
1410
+ child: buildCaptureButton (
1411
+ context: context,
1412
+ constraints: constraints,
1413
+ ),
1402
1414
),
1403
1415
),
1404
1416
if (controller != null &&
@@ -1429,7 +1441,10 @@ class CameraPickerState extends State<CameraPicker>
1429
1441
1430
1442
/// The shooting button.
1431
1443
/// 拍照按钮
1432
- Widget buildCaptureButton (BuildContext context, BoxConstraints constraints) {
1444
+ Widget buildCaptureButton ({
1445
+ required BuildContext context,
1446
+ required BoxConstraints constraints,
1447
+ }) {
1433
1448
final showProgressIndicator =
1434
1449
isCaptureButtonTapDown || MediaQuery .accessibleNavigationOf (context);
1435
1450
@@ -1500,7 +1515,8 @@ class CameraPickerState extends State<CameraPicker>
1500
1515
showProgressIndicator && isShootingButtonAnimate,
1501
1516
duration: pickerConfig.maximumRecordingDuration! ,
1502
1517
size: size,
1503
- ringsColor: theme.indicatorColor,
1518
+ // ignore: deprecated_member_use
1519
+ ringsColor: Theme .of (context).indicatorColor,
1504
1520
ringsWidth: 3 ,
1505
1521
),
1506
1522
),
@@ -1514,13 +1530,14 @@ class CameraPickerState extends State<CameraPicker>
1514
1530
}
1515
1531
1516
1532
Widget buildExposureSlider ({
1533
+ required BuildContext context,
1517
1534
required ExposureMode mode,
1518
1535
required double size,
1519
1536
required double height,
1520
1537
required double gap,
1521
1538
}) {
1522
1539
final bool isLocked = mode == ExposureMode .locked;
1523
- final Color ? color = isLocked ? _lockedColor : theme .iconTheme.color;
1540
+ final color = isLocked ? _lockedColor : Theme . of (context) .iconTheme.color;
1524
1541
final Widget lineWidget = ValueListenableBuilder <bool >(
1525
1542
valueListenable: isFocusPointDisplays,
1526
1543
builder: (_, bool value, Widget ? child) => AnimatedOpacity (
@@ -1580,6 +1597,7 @@ class CameraPickerState extends State<CameraPicker>
1580
1597
/// The area widget for the last exposure point that user manually set.
1581
1598
/// 用户手动设置的曝光点的区域显示
1582
1599
Widget buildFocusingPoint ({
1600
+ required BuildContext context,
1583
1601
required CameraValue cameraValue,
1584
1602
required BoxConstraints constraints,
1585
1603
int quarterTurns = 0 ,
@@ -1612,6 +1630,7 @@ class CameraPickerState extends State<CameraPicker>
1612
1630
const SizedBox (height: verticalGap),
1613
1631
Expanded (
1614
1632
child: buildExposureSlider (
1633
+ context: context,
1615
1634
mode: exposureMode,
1616
1635
size: size,
1617
1636
height: height,
@@ -1698,7 +1717,7 @@ class CameraPickerState extends State<CameraPicker>
1698
1717
size: pointWidth,
1699
1718
color: cameraValue.exposureMode == ExposureMode .locked
1700
1719
? _lockedColor
1701
- : theme. iconTheme.color! ,
1720
+ : Theme . of (context). iconTheme.color,
1702
1721
),
1703
1722
),
1704
1723
),
@@ -1718,10 +1737,10 @@ class CameraPickerState extends State<CameraPicker>
1718
1737
1719
1738
/// The [GestureDetector] widget for setting exposure point manually.
1720
1739
/// 用于手动设置曝光点的 [GestureDetector]
1721
- Widget buildExposureDetector (
1722
- BuildContext context,
1723
- BoxConstraints constraints,
1724
- ) {
1740
+ Widget buildExposureDetector ({
1741
+ required BuildContext context,
1742
+ required BoxConstraints constraints,
1743
+ } ) {
1725
1744
return Semantics (
1726
1745
label: textDelegate.sCameraPreviewLabel (
1727
1746
innerController? .description.lensDirection,
@@ -1812,8 +1831,9 @@ class CameraPickerState extends State<CameraPicker>
1812
1831
children: < Widget > [
1813
1832
preview,
1814
1833
if (pickerConfig.enableSetExposure)
1815
- buildExposureDetector (context, constraints),
1834
+ buildExposureDetector (context: context, constraints : constraints),
1816
1835
buildFocusingPoint (
1836
+ context: context,
1817
1837
cameraValue: cameraValue,
1818
1838
constraints: constraints,
1819
1839
quarterTurns: cameraQuarterTurns,
@@ -1865,11 +1885,11 @@ class CameraPickerState extends State<CameraPicker>
1865
1885
);
1866
1886
}
1867
1887
1868
- Widget buildForegroundBody (
1869
- BuildContext context,
1870
- BoxConstraints constraints,
1888
+ Widget buildForegroundBody ({
1889
+ required BuildContext context,
1890
+ required BoxConstraints constraints,
1871
1891
DeviceOrientation ? deviceOrientation,
1872
- ) {
1892
+ } ) {
1873
1893
final orientation = deviceOrientation ?? MediaQuery .orientationOf (context);
1874
1894
final isPortrait = orientation.toString ().contains ('portrait' );
1875
1895
return SafeArea (
@@ -1888,7 +1908,12 @@ class CameraPickerState extends State<CameraPicker>
1888
1908
child: buildSettingActions (context),
1889
1909
),
1890
1910
const Spacer (),
1891
- ExcludeSemantics (child: buildCaptureTips (innerController)),
1911
+ ExcludeSemantics (
1912
+ child: buildCaptureTips (
1913
+ context: context,
1914
+ controller: innerController,
1915
+ ),
1916
+ ),
1892
1917
Semantics (
1893
1918
sortKey: const OrdinalSortKey (2 ),
1894
1919
hidden: innerController == null ,
@@ -1974,9 +1999,13 @@ class CameraPickerState extends State<CameraPicker>
1974
1999
previewWidget,
1975
2000
if (enableScaledPreview) ...< Widget > [
1976
2001
if (pickerConfig.enableSetExposure)
1977
- buildExposureDetector (context, constraints),
2002
+ buildExposureDetector (
2003
+ context: context,
2004
+ constraints: constraints,
2005
+ ),
1978
2006
buildInitializeWrapper (
1979
2007
builder: (CameraValue v, _) => buildFocusingPoint (
2008
+ context: context,
1980
2009
cameraValue: v,
1981
2010
constraints: constraints,
1982
2011
),
@@ -1988,13 +2017,17 @@ class CameraPickerState extends State<CameraPicker>
1988
2017
),
1989
2018
],
1990
2019
if (innerController == null )
1991
- buildForegroundBody (context, constraints, null )
2020
+ buildForegroundBody (
2021
+ context: context,
2022
+ constraints: constraints,
2023
+ deviceOrientation: null ,
2024
+ )
1992
2025
else
1993
2026
buildInitializeWrapper (
1994
2027
builder: (CameraValue v, _) => buildForegroundBody (
1995
- context,
1996
- constraints,
1997
- v.deviceOrientation,
2028
+ context: context ,
2029
+ constraints: constraints ,
2030
+ deviceOrientation : v.deviceOrientation,
1998
2031
),
1999
2032
),
2000
2033
],
@@ -2005,21 +2038,6 @@ class CameraPickerState extends State<CameraPicker>
2005
2038
2006
2039
@override
2007
2040
Widget build (BuildContext context) {
2008
- Widget body = Builder (builder: buildBody);
2009
- if (isCameraRotated && enableScaledPreview) {
2010
- final MediaQueryData mq = MediaQuery .of (context);
2011
- body = RotatedBox (
2012
- quarterTurns: pickerConfig.cameraQuarterTurns,
2013
- child: MediaQuery (
2014
- data: mq.copyWith (
2015
- size: pickerConfig.cameraQuarterTurns.isOdd
2016
- ? mq.size.flipped
2017
- : mq.size,
2018
- ),
2019
- child: body,
2020
- ),
2021
- );
2022
- }
2023
2041
return AnnotatedRegion <SystemUiOverlayStyle >(
2024
2042
value: const SystemUiOverlayStyle (
2025
2043
systemNavigationBarIconBrightness: Brightness .light,
@@ -2028,9 +2046,25 @@ class CameraPickerState extends State<CameraPicker>
2028
2046
),
2029
2047
child: Theme (
2030
2048
data: theme,
2031
- child: Material (
2032
- color: Colors .black,
2033
- child: body,
2049
+ child: Builder (
2050
+ builder: (context) {
2051
+ Widget body = buildBody (context);
2052
+ if (isCameraRotated && enableScaledPreview) {
2053
+ final MediaQueryData mq = MediaQuery .of (context);
2054
+ body = RotatedBox (
2055
+ quarterTurns: pickerConfig.cameraQuarterTurns,
2056
+ child: MediaQuery (
2057
+ data: mq.copyWith (
2058
+ size: pickerConfig.cameraQuarterTurns.isOdd
2059
+ ? mq.size.flipped
2060
+ : mq.size,
2061
+ ),
2062
+ child: body,
2063
+ ),
2064
+ );
2065
+ }
2066
+ return Material (color: Colors .black, child: body);
2067
+ },
2034
2068
),
2035
2069
),
2036
2070
);
0 commit comments