我在第一次构建页面时收到异常,此构建涉及2个FloatingActionButton.
但是,如果我注释掉2个FloatingActionButton中的一个,运行应用程序,在稍后阶段,我取消注释并继续进行热重新加载,它可以工作.
下面的代码实现了一个图像选择器,并为用户提供了从图库或摄像头中进行选择的选择.
有人看看这个,告诉我我做错了什么?
我突出显示了导致异常的代码部分.
这是代码:
class ProfilePage extends StatefulWidget {
ProfilePage(this.profileId);
final int profileId;
@override
_ProfilePageState createState() => new _ProfilePageState();
}
class _ProfilePageState extends State<ProfilePage> {
var _imageInfo;
@override
void initState() {
_imageInfo = mid.currentProfile['Photo'];
super.initState();
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(Translations
.of(context)
.text(widget.profileId == -1 ? 'profiles_add' : 'profiles_edit')),
actions: <Widget>[
new IconButton(
icon: new Icon(Icons.close),
onPressed: () => Navigator.of(context).pop(null),
),
],
leading: new Container(),
),
body: _build_body(),
);
}
_build_body() {
var profileImage;
profileImage = new Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
new GestureDetector(
child: new Container(
child: new ProfilePicture(imageInfo: _imageInfo),
width: 100.0,
height: 100.0,
alignment: Alignment.center,
),
onTap: () {},
),
// ##################################
new FloatingActionButton(
onPressed: () {
getImage(ImageSource.camera);
},
tooltip: 'Take a Photo',
child: new Icon(Icons.camera_alt)
),
new FloatingActionButton(
onPressed: () {
getImage(ImageSource.gallery);
},
tooltip: 'Pick Image from gallery',
child: new Icon(Icons.photo_library)
),
// ##################################
],
),
);
return new Container(
child: new Column(
children: [profileImage],
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
),
);
}
Future<dynamic> getImage(ImageSource source) async {
var imageFile = await ImagePicker.pickImage(source: source);
if (imageFile != null) {
List<int> imageBytes = imageFile.readAsBytesSync();
String base64Image = base64.encode(imageBytes);
setState(() {
_imageInfo = "base64:" + base64Image;
});
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个例外:
I/flutter ( 9045): ??? EXCEPTION CAUGHT BY SCHEDULER LIBRARY ??????????????????????????????????????????????????????????
I/flutter ( 9045): The following assertion was thrown during a scheduler callback:
I/flutter ( 9045): There are multiple heroes that share the same tag within a subtree.
I/flutter ( 9045): Within each subtree for which heroes are to be animated (typically a PageRoute subtree), each Hero
I/flutter ( 9045): must have a unique non-null tag.
I/flutter ( 9045): In this case, multiple heroes had the following tag: <default FloatingActionButton tag>
I/flutter ( 9045): Here is the subtree for one of the offending heroes:
I/flutter ( 9045): # Hero(tag: <default FloatingActionButton tag>, state: _HeroState#5ea48)
I/flutter ( 9045): # ?KeyedSubtree-[GlobalKey#d064f]
I/flutter ( 9045): # ?RawMaterialButton(state: _RawMaterialButtonState#8f3c6)
I/flutter ( 9045): # ?Semantics(container: true, properties: SemanticsProperties, label: null, value: null, hint: null, renderObject: RenderSemanticsAnnotations#d7c9b relayoutBoundary=up5 NEEDS-PAINT)
I/flutter ( 9045): # ?ConstrainedBox(BoxConstraints(w=56.0, h=56.0), renderObject: RenderConstrainedBox#8437c relayoutBoundary=up6 NEEDS-PAINT)
I/flutter ( 9045): # ?Material(type: button, elevation: 6.0, color: Color(0xff2196f3), textStyle.debugLabel: ((englishLike button).merge(whiteMountainView button)).copyWith, textStyle.inherit: false, textStyle.color: Color(0xffffffff), textStyle.family: Roboto, textStyle.size: 14.0, textStyle.weight: 500, textStyle.letterSpacing: 1.2, textStyle.baseline: alphabetic, textStyle.decoration: TextDecoration.none, shape: CircleBorder(BorderSide(Color(0xff000000), 0.0, BorderStyle.none)), state: _MaterialState#73b5e)
I/flutter ( 9045): # ?_MaterialInterior(duration: 200ms, shape: CircleBorder(BorderSide(Color(0xff000000), 0.0, BorderStyle.none)), elevation: 6.0, color: Color(0xff2196f3), shadowColor: Color(0xff000000), state: _MaterialInteriorState#aa4b9(ticker inactive))
I/flutter ( 9045): # ?PhysicalShape(clipper: ShapeBorderClipper, elevation: 6.0, color: Color(0xff2196f3), shadowColor: Color(0xff000000), renderObject: RenderPhysicalShape#0486d NEEDS-PAINT)
I/flutter ( 9045): # ?_ShapeBorderPaint
I/flutter ( 9045): # ?CustomPaint(renderObject: RenderCustomPaint#7e004 NEEDS-PAINT)
I/flutter ( 9045): # ?NotificationListener<LayoutChangedNotification>
I/flutter ( 9045): # ?_InkFeatures-[GlobalKey#f1e6b ink renderer](renderObject: _RenderInkFeatures#34dbd NEEDS-PAINT)
I/flutter ( 9045): # ?AnimatedDefaultTextStyle(duration: 200ms, debugLabel: ((englishLike button).merge(whiteMountainView button)).copyWith, inherit: false, color: Color(0xffffffff), family: Roboto, size: 14.0, weight: 500, letterSpacing: 1.2, baseline: alphabetic, decoration: TextDecoration.none, softWrap: wrapping at box width, overflow: clip, state: _AnimatedDefaultTextStyleState#c8a96(ticker inactive))
I/flutter ( 9045): # ?DefaultTextStyle(debugLabel: ((englishLike button).merge(whiteMountainView button)).copyWith, inherit: false, color: Color(0xffffffff), family: Roboto, size: 14.0, weight: 500, letterSpacing: 1.2, baseline: alphabetic, decoration: TextDecoration.none, softWrap: wrapping at box width, overflow: clip)
I/flutter ( 9045): # ?InkWell(gestures: [tap], clipped to BoxShape.rectangle, state: _InkResponseState<InkResponse>#32f3c)
I/flutter ( 9045): # ?GestureDetector
I/flutter ( 9045): # ?RawGestureDetector(state: RawGestureDetectorState#d6211(gestures: [tap], behavior: opaque))
I/flutter ( 9045): # ?_GestureSemantics(renderObject: RenderSemanticsGestureHandler#d616c NEEDS-PAINT)
I/flutter ( 9045): # ?Listener(listeners: [down], behavior: opaque, renderObject: RenderPointerListener#8a585 NEEDS-PAINT)
I/flutter ( 9045): # ?Builder
I/flutter ( 9045): # ?IconTheme(IconThemeData#15fa8(color: Color(0xffffffff)))
I/flutter ( 9045): # ?Container(padding: EdgeInsets.zero)
I/flutter ( 9045): # ?Padding(padding: EdgeInsets.zero, renderObject: RenderPadding#45f72 NEEDS-PAINT)
I/flutter ( 9045): # ?Center(alignment: center, widthFactor: 1.0, heightFactor: 1.0, renderObject: RenderPositionedBox#a4315 NEEDS-PAINT)
I/flutter ( 9045): # ?SizedBox.expand(renderObject: RenderConstrainedBox#af3fc relayoutBoundary=up1 NEEDS-PAINT)
I/flutter ( 9045): # ?Tooltip("Pick Image from gallery", vertical offset: 24.0, position: below, state: _TooltipState#36588(ticker inactive))
I/flutter ( 9045): # ?GestureDetector
I/flutter ( 9045): # ?RawGestureDetector(state: RawGestureDetectorState#6cd1d(gestures: [long press], behavior: opaque))
I/flutter ( 9045): # ?Listener(listeners: [down], behavior: opaque, renderObject: RenderPointerListener#aae3f NEEDS-PAINT)
I/flutter ( 9045): # ?Semantics(container: false, properties: SemanticsProperties, label: "Pick Image from gallery", value: null, hint: null, renderObject: RenderSemanticsAnnotations#5fa0a NEEDS-PAINT)
I/flutter ( 9045): # ?Builder
I/flutter ( 9045): # ?IconTheme(IconThemeData#15fa8(color: Color(0xffffffff)))
I/flutter ( 9045): # ?Icon(IconData(U+0E413))
I/flutter ( 9045): # ?Semantics(container: false, properties: SemanticsProperties, label: null, value: null, hint: null, renderObject: RenderSemanticsAnnotations#8a909 NEEDS-PAINT)
I/flutter ( 9045): # ?ExcludeSemantics(excluding: true, renderObject: RenderExcludeSemantics#fc581 NEEDS-PAINT)
I/flutter ( 9045): # ?SizedBox(width: 24.0, height: 24.0, renderObject: RenderConstrainedBox#f68c4 NEEDS-PAINT)
I/flutter ( 9045): # ?Center(alignment: center, renderObject: RenderPositionedBox#c38ac NEEDS-PAINT)
I/flutter ( 9045): # ?RichText(textDirection: ltr, softWrap: wrapping at box width, maxLines: unlimited, text: "?", renderObject: RenderParagraph#8873e relayoutBoundary=up1 NEEDS-PAINT)
I/flutter ( 9045):
I/flutter ( 9045): When the exception was thrown, this was the stack:
I/flutter ( 9045): #0 Hero._allHeroesFor.visitor.<anonymous closure> (package:flutter/src/widgets/heroes.dart:130:13)
I/flutter ( 9045): #1 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:140:10)
I/flutter ( 9045): #2 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3659:14)
I/flutter ( 9045): #3 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:144:15)
I/flutter ( 9045): #4 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:4625:14)
I/flutter ( 9045): #5 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:144:15)
I/flutter ( 9045): #6 MultiChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:4725:16)
I/flutter ( 9045): #7 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:144:15)
I/flutter ( 9045): #8 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:4625:14)
I/flutter ( 9045): #9 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:144:15)
I/flutter ( 9045): #10 MultiChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:4725:16)
I/flutter ( 9045): #11 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:144:15)
I/flutter ( 9045): #12 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3659:14)
I/flutter ( 9045): #13 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:144:15)
I/flutter ( 9045): #14 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3659:14)
I/flutter ( 9045): #15 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:144:15)
I/flutter ( 9045): #16 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3659:14)
I/flutter ( 9045): #17 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:144:15)
I/flutter ( 9045): #18 MultiChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:4725:16)
I/flutter ( 9045): #19 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:144:15)
I/flutter ( 9045): #20 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3659:14)
I/flutter ( 9045): #21 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:144:15)
I/flutter ( 9045): #22 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3659:14)
I/flutter ( 9045): #23 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:144:15)
I/flutter ( 9045): #24 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3659:14)
I/flutter ( 9045): #25 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:144:15)
I/flutter ( 9045): #26 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:4625:14)
I/flutter ( 9045): #27 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:144:15)
I/flutter ( 9045): #28 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3659:14)
I/flutter ( 9045): #29 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:144:15)
I/flutter ( 9045): #30 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:4625:14)
I/flutter ( 9045): #31 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:144:15)
I/flutter ( 9045): #32 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3659:14)
I/flutter ( 9045): #33 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:144:15)
I/flutter ( 9045): #34 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3659:14)
I/flutter ( 9045): #35 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:144:15)
I/flutter ( 9045): #36 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3659:14)
I/flutter ( 9045): #37 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:144:15)
I/flutter ( 9045): #38 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3659:14)
I/flutter ( 9045): #39 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:144:15)
I/flutter ( 9045): #40 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3659:14)
I/flutter ( 9045): #41 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:144:15)
I/flutter ( 9045): #42 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3659:14)
I/flutter ( 9045): #43 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:144:15)
I/flutter ( 9045): #44 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3659:14)
I/flutter ( 9045): #45 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:144:15)
I/flutter ( 9045): #46 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:4625:14)
I/flutter ( 9045): #47 Element.visitChildElements (package:flutter/src/widgets/framework.dart:2625:5)
I/flutter ( 9045): #48 Hero._allHeroesFor (package:flutter/src/widgets/heroes.dart:146:13)
I/flutter ( 9045): #49 HeroController._startHeroTransition (package:flutter/src/widgets/heroes.dart:511:51)
I/flutter ( 9045): #50 HeroController._maybeStartHeroTransition.<anonymous closure> (package:flutter/src/widgets/heroes.dart:492:9)
I/flutter ( 9045): #51 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter ( 9045): #52 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:938:9)
I/flutter ( 9045): #53 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
I/flutter ( 9045): #54 _invoke (dart:ui/hooks.dart:120:13)
I/flutter ( 9045): #55 _drawFrame (dart:ui/hooks.dart:109:3)
I/flutter ( 9045): ????????????????????????????????????????????????????????????????????????????????????????????????????
Run Code Online (Sandbox Code Playgroud)
boe*_*edi 16
好的,我发现添加heroTag: null到FloatingActionButton解决问题的属性.
导致异常的代码部分现在如下,似乎正在起作用.
new FloatingActionButton(
onPressed: () {
getImage(ImageSource.camera);
},
tooltip: 'Take a Photo',
child: new Icon(Icons.camera_alt),
heroTag: null,
),
new FloatingActionButton(
onPressed: () {
getImage(ImageSource.gallery);
},
tooltip: 'Pick Image from gallery',
child: new Icon(Icons.photo_library),
heroTag: null,
),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2267 次 |
| 最近记录: |