import 'dart:ui'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; class ItemTitle extends StatelessWidget { final String text; final String imgPath; final int moreType; final String moreText; final List> items; ItemTitle( { this.text, this.imgPath, this.moreText = "", this.moreType = 0, this.items, this.onChanged, this.onTap}); @override Widget build(BuildContext context) { return Container( margin: EdgeInsets.only(left: 16, right: 17, top: 10, bottom: 10), alignment: Alignment.center, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, children: [ Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: [ Text( text, textAlign: TextAlign.center, style: TextStyle( color: Colors.black, fontSize: 16, fontWeight: FontWeight.bold, ), ), SizedBox( width: 8, ), Image.asset( imgPath, width: 24, height: 24, ), ], ), if (moreText != "") buildMore() ], ), ); } final GestureTapCallback onTap; final Function(String) onChanged; Widget buildMore() { return moreType == 0 ? GestureDetector( onTap: onTap, child: Container( padding: EdgeInsets.only(left: 8, right: 8, top: 2, bottom: 2), decoration: BoxDecoration( color: Colors.white, boxShadow: [ BoxShadow( color: Colors.black.withAlpha(25), offset: Offset(0, 1), blurRadius: 12, spreadRadius: 0) ], borderRadius: BorderRadius.all(Radius.circular(2))), child: Row( children: [ Text( moreText, style: TextStyle(fontSize: 12), ), Icon( moreType == 0 ? Icons.keyboard_arrow_right : (Icons.keyboard_arrow_down), size: 16, ) ], ), ), ) : Container( padding: EdgeInsets.only(left: 10, right: 10), child: DropdownButton( items: items, value: moreText, onChanged: onChanged, ), ); } }