home_page.dart 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // Copyright 2019 The FlutterCandies author. All rights reserved.
  2. // Use of this source code is governed by an Apache license that can be found
  3. // in the LICENSE file.
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter/semantics.dart';
  6. import 'package:flutter/services.dart';
  7. import 'package:wechat_camera_picker/wechat_camera_picker.dart';
  8. import '../extensions/l10n_extensions.dart';
  9. import '../main.dart';
  10. import '../models/picker_method.dart';
  11. import '../widgets/method_list_view.dart';
  12. import '../widgets/selected_assets_list_view.dart';
  13. class HomePage extends StatefulWidget {
  14. const HomePage({super.key});
  15. @override
  16. State<HomePage> createState() => _MyHomePageState();
  17. }
  18. class _MyHomePageState extends State<HomePage> {
  19. final ValueNotifier<bool> isDisplayingDetail = ValueNotifier<bool>(true);
  20. List<AssetEntity> assets = <AssetEntity>[];
  21. Future<void> selectAssets(PickMethod model) async {
  22. final result = await model.method(context);
  23. if (result != null) {
  24. assets = [...assets, result];
  25. if (mounted) {
  26. setState(() {});
  27. }
  28. }
  29. }
  30. Widget header(BuildContext context) {
  31. return Container(
  32. margin: const EdgeInsetsDirectional.only(top: 30),
  33. padding: const EdgeInsets.symmetric(horizontal: 20.0),
  34. height: 60,
  35. child: Row(
  36. mainAxisAlignment: MainAxisAlignment.center,
  37. children: <Widget>[
  38. AspectRatio(
  39. aspectRatio: 1,
  40. child: Hero(
  41. tag: 'LOGO',
  42. child: Image.asset('assets/flutter_candies_logo.png'),
  43. ),
  44. ),
  45. const SizedBox(width: 10),
  46. Flexible(
  47. child: Column(
  48. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  49. crossAxisAlignment: CrossAxisAlignment.start,
  50. children: <Widget>[
  51. Semantics(
  52. sortKey: const OrdinalSortKey(0),
  53. child: FittedBox(
  54. child: Text(
  55. context.l10n.appTitle,
  56. style: Theme.of(context).textTheme.titleLarge,
  57. overflow: TextOverflow.fade,
  58. maxLines: 1,
  59. ),
  60. ),
  61. ),
  62. Semantics(
  63. sortKey: const OrdinalSortKey(0.1),
  64. child: Text(
  65. context.l10n.appVersion(
  66. packageVersion ?? context.l10n.appVersionUnknown,
  67. ),
  68. style: Theme.of(context).textTheme.bodySmall,
  69. ),
  70. ),
  71. ],
  72. ),
  73. ),
  74. const SizedBox(width: 20),
  75. ],
  76. ),
  77. );
  78. }
  79. @override
  80. Widget build(BuildContext context) {
  81. return AnnotatedRegion<SystemUiOverlayStyle>(
  82. value: Theme.of(context).brightness == Brightness.dark
  83. ? SystemUiOverlayStyle.light
  84. : SystemUiOverlayStyle.dark,
  85. child: Scaffold(
  86. body: SafeArea(
  87. child: Column(
  88. children: <Widget>[
  89. header(context),
  90. Padding(
  91. padding: const EdgeInsets.all(20.0),
  92. child: Text(
  93. context.l10n.pickMethodNotice(
  94. 'lib/models/picker_method.dart',
  95. ),
  96. ),
  97. ),
  98. Expanded(
  99. child: MethodListView(
  100. pickMethods: pickMethods(context),
  101. onSelectMethod: selectAssets,
  102. ),
  103. ),
  104. if (assets.isNotEmpty)
  105. SelectedAssetsListView(
  106. assets: assets,
  107. isDisplayingDetail: isDisplayingDetail,
  108. onRemoveAsset: (int index) {
  109. assets.removeAt(index);
  110. setState(() {});
  111. },
  112. ),
  113. ],
  114. ),
  115. ),
  116. ),
  117. );
  118. }
  119. }