Closed
Description
Bug Description
the value of the '_selectedIndex != null ? _selectedIndex == index : false' is same with '_selectedIndex==index' in debug mode but different in profile or release mode.
Flutter Version
Flutter 2.10.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 097d3313d8 (4 days ago) • 2022-02-18 19:33:08 -0600
Engine • revision a83ed0e5e3
Tools • Dart 2.16.1 • DevTools 2.9.2
Steps to Reproduce
- flutter run
the expr_selectedIndex != null ? _selectedIndex == index : false
is equal to_selectedIndex==index
- flutter run --profile or flutter run --release
the expr_selectedIndex != null ? _selectedIndex == index : false
is always false
Code sample
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(primarySwatch: Colors.blue),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int? _selectedIndex;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Bug Test")),
body: Column(
children: [
const Padding(
padding: EdgeInsets.all(20),
child: Text(
"the value of the '_selectedIndex != null ? _selectedIndex == index : false' is same with '_selectedIndex==index' in debug mode but different in profile or release mode",
style: TextStyle(fontSize: 16),
)),
Expanded(
child: ListView.builder(
itemCount: 2,
itemBuilder: (context, index) {
return ListTile(
onTap: () {
setState(() => _selectedIndex = index);
},
//_selectedIndex != null ? _selectedIndex == index : false
title: Text(
"selected:${_selectedIndex != null ? _selectedIndex == index : false}"),
//_selectedIndex == index
subtitle: Text("selected:${_selectedIndex == index}"),
);
})) ],
),
);
}
}