Andrew P
Andrew P

Reputation: 231

Flutter expansion tile disappears when clicked

I am using flutter and I'm just a beginner. I have multi List that I want to eventually put in a menu in a drawer but I am having a visual problem with it.

I have included a picture of what it looks like. When you click on the title to drop down the list the title itself disappears. Doesn't seem to be the default behaviour from other tutorials I've seen off the internet.

Can someone help me with this?

My code looks like this:

import 'package:flutter/material.dart';

class HomePage extends StatelessWidget {
 @override
Widget build(BuildContext context) {
return Scaffold(
  appBar: AppBar(
    iconTheme: IconThemeData(color: Colors.white),
    title: Text(
      'Home',
      style: TextStyle(color: Colors.white),
    ),
  ),
  body: new ListView.builder(
    itemBuilder: (BuildContext context, int index) {
      return new StuffInTiles(listofTiles[index]);
    },
    itemCount: listofTiles.length,
  ),
);
}
}

class StuffInTiles extends StatelessWidget {
final MyTile myTile;

StuffInTiles(this.myTile);

@override
Widget build(BuildContext context) {
   return _buildTiles(myTile);
}

Widget _buildTiles(MyTile t) {
if (t.children.isEmpty) return new ListTile(title: new Text(t.title));
return new ExpansionTile(
  key: new PageStorageKey<MyTile>(t),
  title: new Text(t.title),
  children: t.children.map(_buildTiles).toList(),
);
}
}

class MyTile {
String title;
List<MyTile> children;

MyTile(this.title, [this.children = const <MyTile>[]]);
}

List<MyTile> listofTiles = <MyTile>[
new MyTile('Animals', <MyTile>[
new MyTile('Dogs', <MyTile>[new MyTile('dog one '), new MyTile('dog two')])
]) 
];

flutter app missing title when clicked

Here is my main.dart file

import 'package:actionhrm/pages/login.dart';
import 'package:flutter/material.dart';
import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';
import 'package:flutter/services.dart';




 void main() => runApp(new MyApp());

 class MyApp extends StatelessWidget {

 MyApp() {
   //changeStatusColor(Color(0xFF28ace2));
 }

 changeStatusColor(Color color) async {
   try {
     await FlutterStatusbarcolor.setStatusBarColor(color);
   } on PlatformException catch (e) {
     print(e);
   }
 }

 // This widget is the root of your application.
 @override
 Widget build(BuildContext context) {
   return new MaterialApp(
     theme: new ThemeData(
       primaryColor: Color(0xFF28ace2),
       brightness: Brightness.light,
       accentColor: Colors.white,
       cardColor: Colors.white,

     ),
     home: LoginPage(),
   );
 }
}

One thing I don't understand is that when I wrap the HomePage build widget in a Material App it works but I didn't think you were supposed to do that

Just a note the main.dart file loads the login page and then the login page loads the home page.

If you add HomePage to home in the Material App it won't work!

Upvotes: 1

Views: 1665

Answers (1)

Andrew P
Andrew P

Reputation: 231

I found my own answer. When your beginning it's good not to fool around too much with things you dont' understand. I had

accentColor: Colors.white,

Added to my theme data causing it to disappear amongst the white behind it. Sorry Stupid mistake

Upvotes: 3

Related Questions