The code:
import ‘package:flutter/material.dart’;
class Story extends StatelessWidget {
final int index;
final Uri postURI;
const Story(this.index, this.postURI, {Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return InkWell(
child: Stack(
alignment: Alignment.topRight,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Image.network(
“$postURI”,
fit: BoxFit.cover,
),
),
if (index % 3 == 0)
const Padding(
padding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 4),
child: Stack(
alignment: Alignment.center,
children: [
CircleAvatar(
backgroundColor: Colors.white,
maxRadius: 7,
),
CircleAvatar(
backgroundColor: Colors.red,
maxRadius: 5,
),
],
),
),
],
),
);
}
}
The Error:
25:22: Error: Cannot invoke a non-‘const’ constructor where a const expression is expected.
Try using a constructor or factory that is ‘const’.
child: Stack(
^^^^^
Target kernel_snapshot failed: Exception
FAILURE: Build failed with an exception.
-
Where:
Script ‘/Users/seifadine/Developer/flutter/packages/flutter_tools/gradle/flutter.gradle’ line: 1151 -
What went wrong:
Execution failed for task ‘:app:compileFlutterBuildDebug’.
Process ‘command ‘/Users/seifadine/Developer/flutter/bin/flutter’’ finished with non-zero exit value 1
- Try:
Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.
- Get more help at https://help.gradle.org
BUILD FAILED in 2s
Exception: Gradle task assembleDebug failed with exit code 1