Upgrade Skill Di ITBOX Jadi Lebih Hemat
Special Diskon 50%
Sampai 16 November 2026!
Hari
Jam
Menit
Detik
GARUDABOX

Error saat klik tombol + di home screen

Beranda › Forums › Belajar Flutter Mobile Apps Tingkat Menengah › Error saat klik tombol + di home screen

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #169628
    Rendi Andika
    Participant

      Malam coach, saya ada problem saat klik button +,
      muncul error sebagai berikut.

      Bad state: No element
      See also: https://flutter.dev/
      docs/testing/errors

      berikut code home_screen

      import ‘package:flutter/material.dart’;
      import ‘package:flutter_state/models/note.dart’;
      import ‘package:flutter_state/screens/add_or_detail_screen.dart’;
      import ‘package:flutter_state/widgets/notes_grid.dart’;

      class HomeScreen extends StatefulWidget {
      //const HomeScreen({Key key}) : super(key: key);

      @override
      State<HomeScreen> createState() => _HomeScreenState();
      }

      class _HomeScreenState extends State<HomeScreen> {
      @override
      Widget build(BuildContext context) {
      return Scaffold(
      appBar: AppBar(
      title: Text(‘Notes’),
      ),
      body: NotesGrid(),
      floatingActionButton: FloatingActionButton(
      onPressed: () {
      Navigator.of(context).pushNamed(AddOrDetailScreen.routeName);
      },
      child: Icon(Icons.add),
      ),
      );
      }
      }

      dan code add_or_detail_screen

      import ‘package:flutter/material.dart’;
      import ‘package:flutter_state/models/note.dart’;
      import ‘package:flutter_state/providers/notes.dart’;
      import ‘package:intl/intl.dart’;
      import ‘package:provider/provider.dart’;

      class AddOrDetailScreen extends StatefulWidget {
      static const routeName = ‘/addOrDetailScreen’;
      @override
      State<AddOrDetailScreen> createState() => _AddOrDetailScreenState();
      }

      class _AddOrDetailScreenState extends State<AddOrDetailScreen> {
      Note _note = Note(
      id: null,
      title: ”,
      note: ”,
      updatedAt: null,
      createdAt: null,
      );

      bool init = true;

      final _formKey = GlobalKey<FormState>();

      void submitNote() {
      _formKey.currentState.save();
      final now = DateTime.now();
      _note = _note.copyWith(updatedAt: now, createdAt: now);
      final notesProvider = Provider.of<Notes>(context, listen: false);
      if (_note.id == null) {
      notesProvider.addNote(_note);
      } else {
      notesProvider.updateNote(_note);
      }
      Navigator.of(context).pop();
      }

      @override
      void didChangeDependencies() {
      if (init) {
      String id = ModalRoute.of(context).settings.arguments as String;
      _note = Provider.of<Notes>(context).getNote(id);
      init = false;
      }
      super.didChangeDependencies();
      }

      String _convertDate(DateTime dateTime) {
      int diff = DateTime.now().difference(dateTime).inDays;
      if (diff > 0) return DateFormat(‘dd-MM-yyyy’).format(dateTime);

      return DateFormat(‘hh:mm’).format(dateTime);
      }

      @override
      Widget build(BuildContext context) {
      return Scaffold(
      appBar: AppBar(
      actions: [
      TextButton(
      onPressed: submitNote,
      child: Text(‘Simpan’),
      )
      ],
      ),
      body: Stack(
      children: [
      Container(
      height: double.infinity,
      padding: EdgeInsets.all(12),
      child: SingleChildScrollView(
      child: Form(
      key: _formKey,
      child: Column(
      children: [
      TextFormField(
      initialValue: _note.title,
      decoration: InputDecoration(
      hintText: ‘Judul’,
      border: InputBorder.none,
      ),
      onSaved: (value) {
      _note = _note.copyWith(title: value);
      },
      ),
      TextFormField(
      initialValue: _note.note,
      decoration: InputDecoration(
      hintText: ‘Tulis Catatan Disini…’,
      border: InputBorder.none),
      onSaved: (value) {
      _note = _note.copyWith(note: value);
      },
      maxLines: null,
      ),
      ],
      ),
      ),
      ),
      ),
      Positioned(
      bottom: 10,
      right: 10,
      child: Text(‘Terakhir Diubah ${_convertDate(_note.updatedAt)}’)),
      ],
      ),
      );
      }
      }

      #169865
      Anonymous

        Halo, untuk error ini nanti di video ada dijelasin ya.
        bisa coba dilanjutkan terlebih dahulu videonya.

        #169866
        Anonymous

          Halo, untuk error ini nanti di video ada dijelasin ya.
          bisa coba dilanjutkan terlebih dahulu videonya.

        Viewing 3 posts - 1 through 3 (of 3 total)
        • You must be logged in to reply to this topic.
        Shopping cart0
        There are no products in the cart!
        Continue shopping