116 lines
3.4 KiB
Dart
116 lines
3.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'character.dart';
|
|
import 'character_list_extension.dart';
|
|
import 'default_character.dart';
|
|
|
|
void main() => runApp(MyApp());
|
|
|
|
class MyApp extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'Identity V Characters',
|
|
home: MyHomePage(title: 'Персонажи Identity V'),
|
|
);
|
|
}
|
|
}
|
|
|
|
class MyHomePage extends StatefulWidget {
|
|
MyHomePage({Key? key, required this.title}) : super(key: key);
|
|
|
|
final String title;
|
|
|
|
@override
|
|
_MyHomePageState createState() => _MyHomePageState();
|
|
}
|
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
|
final List<Character> _characters = [];
|
|
final _nameController = TextEditingController();
|
|
CharacterType _selectedType = CharacterType.Survivor; // По умолчанию - выживший
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(widget.title),
|
|
),
|
|
body: Column(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: TextField(
|
|
controller: _nameController,
|
|
decoration: InputDecoration(
|
|
labelText: 'Имя персонажа',
|
|
),
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Row(
|
|
children: [
|
|
Radio<CharacterType>(
|
|
value: CharacterType.Survivor,
|
|
groupValue: _selectedType,
|
|
onChanged: (value) {
|
|
setState(() {
|
|
_selectedType = value!;
|
|
});
|
|
},
|
|
),
|
|
Text('Выживший'),
|
|
Radio<CharacterType>(
|
|
value: CharacterType.Hunter,
|
|
groupValue: _selectedType,
|
|
onChanged: (value) {
|
|
setState(() {
|
|
_selectedType = value!;
|
|
});
|
|
},
|
|
),
|
|
Text('Охотник'),
|
|
],
|
|
),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
final name = _nameController.text.trim();
|
|
if (name.isNotEmpty) {
|
|
setState(() {
|
|
_characters.add(
|
|
_selectedType == CharacterType.Survivor
|
|
? Survivor(name: name)
|
|
: Hunter(name: name),
|
|
);
|
|
_nameController.clear();
|
|
});
|
|
}
|
|
},
|
|
child: Text('Добавить персонажа'),
|
|
),
|
|
Expanded(
|
|
child: ListView.builder(
|
|
itemCount: _characters.length,
|
|
itemBuilder: (context, index) {
|
|
final character = _characters[index];
|
|
return ListTile(
|
|
title: Text(character.name),
|
|
subtitle: Text(character.getInfo()),
|
|
trailing: IconButton(
|
|
icon: Icon(Icons.delete),
|
|
onPressed: () {
|
|
setState(() {
|
|
_characters.removeAt(index);
|
|
});
|
|
},
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
} |