Home > OS >  flutter appbar is disappeared
flutter appbar is disappeared

Time:09-27

my appbar is disappeared when i go new page using navigator actually, there was a yellow underline on the new page's text. I found that's reason is the page didn't have Material. so i added the Material Widget on that, so I could fixed the problem of text underline. i think appbar disappeared problem also relates with Material, but even i wrapped the code with Material widget, still the problem is not solved. what can i do?

here is the navigator code. exhibition[i] is what i wanted to transmit to new page(=DetailScreen)

InkWell(
        onTap: () {Navigator.push(
          context,
          MaterialPageRoute(builder: (context)=>DetailScreen(exhibition: exhibitions[i])),
        );

And the below is DetailScreen(new page)'s code.

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'model_exhibitions.dart';

class DetailScreen extends StatefulWidget {
  final Exhibition exhibition;

  DetailScreen({required this.exhibition});

  State<DetailScreen> createState() => _DetailScreenState();
}

class _DetailScreenState extends State<DetailScreen> {
  bool bookmark = false;

  @override
  void initState() {
    super.initState();
    bookmark = widget.exhibition.bookmark;
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      child: SingleChildScrollView(
        padding: EdgeInsets.fromLTRB(20, 40, 0, 0),
        child: Row( ...

Thank you for your help sincerely

CodePudding user response:

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'model_exhibitions.dart';

class DetailScreen extends StatefulWidget {
  final Exhibition exhibition;

  DetailScreen({required this.exhibition});

  State<DetailScreen> createState() => _DetailScreenState();
}

class _DetailScreenState extends State<DetailScreen> {
  bool bookmark = false;

  @override
  void initState() {
    super.initState();
    bookmark = widget.exhibition.bookmark;
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      child: Scaffold(   //add scaffold

       body: SingleChildScrollView(
        padding: EdgeInsets.fromLTRB(20, 40, 0, 0),
        child: Row( ...

It will not work without scaffold.

I think you are not getting what scaffold is and how it's behaviour is?

Scaffold is a widget which provides your screen/route a default behaviour similar to your android/ios screens like AppBar, Body, Title, FloatingActionButton, Drawer etc.

So that you do not have to make yourself a new structure.

If you are not using scaffold, then your page will act like a plain body structure in which you have to fill custom widgets as per your requirements.

  • Related