11import 'package:flutter/material.dart' ;
2+ import 'package:stelaris/api/model/sound/sound_file_source.dart' ;
23import 'package:stelaris/feature/base/button/cancel_button.dart' ;
34import 'package:stelaris/feature/sound/modal/section/base_section.dart' ;
45import 'package:stelaris/feature/sound/modal/type/integer_fields_section.dart' ;
@@ -8,38 +9,54 @@ import 'package:stelaris/feature/sound/modal/type/volume_section.dart';
89import 'section/string_field_section.dart' ;
910
1011class SoundFileModal extends StatefulWidget {
11- final void Function ({
12- required String name,
13- required double volume,
14- required double pitch,
15- required int weight,
16- required bool stream,
17- required int attenuationDistance,
18- required bool preload,
19- required String type,
20- })?
21- onSave;
2212
23- final bool create;
13+ const SoundFileModal ({
14+ required this .create,
15+ required this .onSave,
16+ this .initialData,
17+ super .key,
18+ });
2419
25- const SoundFileModal ({required this .create, required this .onSave, super .key});
20+ final void Function (SoundFileSource soundFile)? onSave;
21+ final bool create;
22+ final SoundFileSource ? initialData;
2623
2724 @override
2825 State <SoundFileModal > createState () => _SoundFileModalState ();
2926}
3027
28+
3129class _SoundFileModalState extends State <SoundFileModal > {
32- String _name = '' ;
33- double _volume = 1 ;
34- double _pitch = 1 ;
35- int _weight = 1 ;
36- bool _stream = true ;
37- int _attenuationDistance = 16 ;
38- bool _preload = false ;
39- String _type = 'file' ;
30+ late String _name;
31+ late double _volume;
32+ late double _pitch;
33+ late int _weight;
34+ late bool _stream;
35+ late int _attenuationDistance;
36+ late bool _preload;
37+ late String _type;
4038
4139 final _formKey = GlobalKey <FormState >();
4240
41+ @override
42+ void initState () {
43+ super .initState ();
44+ debugPrint ('Read data from' );
45+ if (widget.initialData != null ) {
46+ debugPrint ('Exsts' );
47+ debugPrint (widget.initialData! .toString ());
48+ }
49+ final data = widget.initialData;
50+ _name = data? .name ?? '' ;
51+ _volume = data? .volume ?? 1 ;
52+ _pitch = data? .pitch ?? 1 ;
53+ _weight = data? .weight ?? 1 ;
54+ _stream = true ;
55+ _attenuationDistance = data? .attenuationDistance ?? 16 ;
56+ _preload = data? .preload ?? false ;
57+ _type = data? .type ?? 'file' ;
58+ }
59+
4360 @override
4461 Widget build (BuildContext context) {
4562 final media = MediaQuery .of (context);
@@ -67,7 +84,10 @@ class _SoundFileModalState extends State<SoundFileModal> {
6784 style: Theme .of (context).textTheme.titleLarge,
6885 ),
6986 const SizedBox (height: 24 ),
70- const StringInputSection (),
87+ StringInputSection (
88+ initialValue: _name,
89+ onUpdate: (value) => _name = value,
90+ ),
7191 const SizedBox (height: 16 ),
7292 VolumeSection (
7393 initialPitch: _pitch,
@@ -133,15 +153,17 @@ class _SoundFileModalState extends State<SoundFileModal> {
133153 onPressed: () {
134154 if (_formKey.currentState? .validate () ?? false ) {
135155 widget.onSave? .call (
136- name: _name,
137- volume: _volume,
138- pitch: _pitch,
139- weight: _weight,
140- stream: _stream,
141- attenuationDistance: _attenuationDistance,
142- preload: _preload,
143- type: _type,
156+ SoundFileSource (
157+ name: _name,
158+ volume: _volume,
159+ pitch: _pitch,
160+ weight: _weight,
161+ attenuationDistance: _attenuationDistance,
162+ preload: _preload,
163+ type: _type,
164+ ),
144165 );
166+
145167 Navigator .pop (context);
146168 }
147169 },
0 commit comments