Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
6.1 kB
1
Indexable
Never
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '1302200010 - Asyrafbilal Fadhila Bhinar Jaya',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'TP06 PPB'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  var titleInput = TextEditingController();
  var platInput = TextEditingController();
  var langInput = TextEditingController();

  static const List<String> list = <String>['blue', 'green', 'yellow'];
  List<Map<String, dynamic>> app = [
    {
      "name": "Native app",
      "platform": "Android, iOS, Web, Javascript, Dart",
      "lang": "Java, Go, C, C++, C#, Python",
      "color": "red"
    },
    {
      "name": "Hybrid App",
      "platform": "Android, iOS, Web, Javascript, Dart",
      "lang": "Java, Go, C, C++, C#, Python",
      "color": "grey"
    }
  ];
  colorPick(String color) {
    switch (color) {
      case "red":
        return Colors.red;
      case "grey":
        return Colors.grey;
      case "blue":
        return Colors.blue;
      case "green":
        return Colors.green;
      case "yellow":
        return Colors.yellow;
    }
  }
  String dropdownValue = list.first;
   

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: ListView.builder(
            itemCount: app.length,
            itemBuilder: (BuildContext context, int index) {
              return ListTile(
                contentPadding: EdgeInsets.all(10),
                leading: CircleAvatar(
                  backgroundColor: colorPick('${app[index]["color"]}'),
                ),
                title: Text(
                  '${app[index]["name"]}',
                  style: TextStyle(color: Colors.blue, fontSize: 20),
                ),
                onTap: () {
                  showDialog(
                    context: context,
                    builder: (BuildContext context) {
                      return AlertDialog(
                        title: Text('Detail'),
                        content: Column(
                          mainAxisSize: MainAxisSize.min,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(
                              '${app[index]["name"]}',
                              style:
                                  TextStyle(color: Colors.blue, fontSize: 20),
                            ),
                            Text('${app[index]["platform"]}'),
                            Text('${app[index]["lang"]}'),
                          ],
                        ),
                        actions: [
                          TextButton(
                            child: Text('Close'),
                            onPressed: () {
                              Navigator.of(context).pop();
                            },
                          ),
                        ],
                      );
                    },
                  );
                },
              );
            }),

            floatingActionButton: FloatingActionButton(
        onPressed: () {
          final snackBar = SnackBar(
            content: const Text('Add new tech?'),
            
            action: SnackBarAction(
              label: 'add',
              onPressed: () {
                // _addNewTech;
                showDialog(context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text('Add New Tech'),
          content: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            TextFormField(
                decoration: const InputDecoration(
                border: UnderlineInputBorder(),
                labelText: 'Tech Name',
              ),
              controller: titleInput,
            ),
            TextFormField(
                decoration: const InputDecoration(
                border: UnderlineInputBorder(),
                labelText: 'Platform',
              ),
              controller: platInput,
            ),
            TextFormField(
                decoration: const InputDecoration(
                border: UnderlineInputBorder(),
                labelText: 'Lang',
              ),
              controller: langInput,
            ),
            DropdownButton(
              value: dropdownValue,
              onChanged: (String? newValue){
                setState(() {
                dropdownValue = newValue!;
                });
              },
              items: list.map<DropdownMenuItem<String>>((String value) {
                return DropdownMenuItem<String>(
                  value: value,
                  child: Text(value),
                );
              }).toList(),
            ),
          ]
        ),
        actions: [
          TextButton(
            child: Text('submit'),
            onPressed: () {
              setState(() {
                app.add({"name": titleInput.text,
                "platform": platInput.text,
                "lang": langInput.text});
              });
              Navigator.of(context).pop();
            },
          ),
        ],
        );
      });
              },
              
            ),
          );

          // Find the ScaffoldMessenger in the widget tree
          // and use it to show a SnackBar.
          ScaffoldMessenger.of(context).showSnackBar(snackBar);
        },
        child: const Icon(Icons.add),
      ),
    );
  }
}