11102 Commits

Author SHA1 Message Date
Greg Spencer
301577a34f
Fixing a memory leak in About box/dialog overlays (#130842)
## Description

Fix three memory leaks detected by `about_test.dart`, but were really in the `Route` and `OverlayEntry` classes.

## Related Issues
 - Fixes https://github.com/flutter/flutter/issues/130354

## Tests
 - Updates about_test.dart to not ignore the leaks anymore.
2023-08-15 21:58:21 +00:00
Srujan Gaddam
03b9911a07
Make completeError be a proper JS function (#132492)
Function.toJS will start requiring that the function accept and return
JS types only.

Allows https://dart-review.googlesource.com/c/sdk/+/316867 to land.
2023-08-15 11:50:31 -07:00
Ian Hickson
cc0d63ea66
Further clarification of the TextSelectionControls migration (#132539)
Further follow-up for https://github.com/flutter/flutter/issues/122421.
2023-08-15 16:37:16 +00:00
Ian Hickson
ccdf826466
PaginatedDataTable improvements (#131374)
- slightly improved assert message when row cell counts don't match column count.
- more breadcrumbs in API documentation. more documentation in general.
- added more documentation for the direction of the "ascending" arrow.
- two samples for PaginatedDataTable.
- make PaginatedDataTable support hot reloading across changes to the number of columns.
- introduce matrix3MoreOrLessEquals. An earlier version of this PR used it in tests, but eventually it was not needed. The function seems useful to keep though.
2023-08-15 00:55:07 +00:00
Renzo Olivares
9a39a5d697
Selection area should move selection word by word on a long press drag (#132518)
On native iOS and Android when long pressing and then dragging the selection expands word by word. Before this change `SelectionArea` expanded the selection character by character on a long press drag.

Fixes #104603
2023-08-14 22:51:05 +00:00
Casey Hillers
7ce2d83b84
Revert "Fix PopupMenuItem & CheckedPopupMenuItem has redundant ListTile padding and update default horizontal padding for Material 3" (#132457)
Reverts flutter/flutter#131609

b/295497265 - This broke Google Testing. We'll need the internal patch
before landing as there's a large number of customer codebases impacted.
2023-08-13 14:27:01 -07:00
LongCatIsLooong
881945ddb8
Read --dart-define in RendererBinding.initInstances() (#132408)
Move `SKPARAGRAPH_REMOVE_ROUNDING_HACK` reading to the framework from `dart:ui` so `flutter run --dart-define="SKPARAGRAPH_REMOVE_ROUNDING_HACK=false"` works
2023-08-12 01:56:22 +00:00
Renzo Olivares
457d00449d
Add double click and double click + drag gestures to SelectionArea (#124817)
Adds double click to select a word.
Adds double click + drag to select word by word.

https://user-images.githubusercontent.com/948037/234363577-941c36bc-ac42-4b7f-84aa-26b106c9ff05.mov

Partially fixes #104552
2023-08-11 21:08:39 +00:00
Ian Hickson
a2e2574941
Remove the fast reassemble / single widget reload feature (#132255)
Fixes https://github.com/flutter/flutter/issues/132157
2023-08-10 21:48:06 +00:00
Renzo Olivares
73e0dbf5f4
TextField should correctly resolve provided style for material states (#132330)
This change makes sure the style provided through the `TextField`s `style` parameter is resolved for material states before merging it with defaults.

Fixes #132212
2023-08-10 21:25:05 +00:00
Ian Hickson
1e35d3a6b7
setState documentation (#132090)
Fixes https://github.com/flutter/flutter/issues/12296
2023-08-10 21:14:06 +00:00
Ian Hickson
4d42f1a852
GridView sample code (#131900) 2023-08-10 20:53:05 +00:00
LongCatIsLooong
e1fd2ace92
TextPainter migration cleanup (#132317)
Undo temporary changes made in #132094
2023-08-10 20:18:51 +00:00
Ian Hickson
f9a578dd82
An example of parentData usage. (#131818) 2023-08-10 19:40:06 +00:00
Fré Dumazy
e972d5a3f6
Add hasInteractedByUser getter in FormField (#131539)
Adds a getter to access the value of the private `RestorableBool _hasInteractedByUser`.

*List which issues are fixed by this PR. You must list at least one issue.*
Fixes #131538
2023-08-10 18:53:56 +00:00
Taha Tesser
96e02c61dc
Fix PopupMenuItem & CheckedPopupMenuItem has redundant ListTile padding and update default horizontal padding for Material 3 (#131609)
fixes [`PopupMenuItem` adds redundant padding when using `ListItem`](https://github.com/flutter/flutter/issues/128553)

### Description

- Fixed redundant `ListTile` padding when using `CheckedPopupMenuItem` or  `PopupMenuItem`  with the `ListTile` child for complex popup menu items as suggested in the docs.
- Updated default horizontal padding for popup menu items.

### Code sample

<details> 
<summary>expand to view the code sample</summary> 

```dart
import 'package:flutter/material.dart';

/// Flutter code sample for [PopupMenuButton].

// This is the type used by the popup menu below.
enum SampleItem { itemOne, itemTwo, itemThree }

void main() => runApp(const PopupMenuApp());

class PopupMenuApp extends StatelessWidget {
  const PopupMenuApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(useMaterial3: true),
      home: const PopupMenuExample(),
    );
  }
}

class PopupMenuExample extends StatefulWidget {
  const PopupMenuExample({super.key});

  @override
  State<PopupMenuExample> createState() => _PopupMenuExampleState();
}

class _PopupMenuExampleState extends State<PopupMenuExample> {
  SampleItem? selectedMenu;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('PopupMenuButton')),
      body: Center(
        child: SizedBox(
          width: 150,
          height: 100,
          child: Align(
            alignment: Alignment.topLeft,
            child: PopupMenuButton<SampleItem>(
              initialValue: selectedMenu,
              // Callback that sets the selected popup menu item.
              onSelected: (SampleItem item) {
                setState(() {
                  selectedMenu = item;
                });
              },
              itemBuilder: (BuildContext context) =>
                  <PopupMenuEntry<SampleItem>>[
                const PopupMenuItem<SampleItem>(
                  value: SampleItem.itemOne,
                  child: Text('PopupMenuItem'),
                ),
                const CheckedPopupMenuItem<SampleItem>(
                  checked: true,
                  value: SampleItem.itemTwo,
                  child: Text('CheckedPopupMenuItem'),
                ),
                const PopupMenuItem<SampleItem>(
                  value: SampleItem.itemOne,
                  child: ListTile(
                    leading: Icon(Icons.cloud),
                    title: Text('ListTile'),
                    contentPadding: EdgeInsets.zero,
                    trailing: Icon(Icons.arrow_right_rounded),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
``` 
	
</details>

### Before

![image](https://github.com/flutter/flutter/assets/48603081/aad15ffb-ca11-4997-81d1-b46288161a4e)

- Default horizontal padding is the same as M2 (16.0), while the specs use a smaller value (12.0)
- `ListTile` nested by default in `CheckedPopupMenuItem` has redundant padding
- `PopupMenuItem` using `ListTile` as a child for complex menu items contains redundant padding.

![Screenshot 2023-07-31 at 17 17 08](https://github.com/flutter/flutter/assets/48603081/75ad1fe5-e051-42ba-badf-e20c799dee96)

### After 

- Default horizontal padding is updated for Material 3.
- `PopupMenuItem` & `CheckedPopupMenuItem` override `ListTile` padding (similar to how `ExpansionTile` overrides `ListTile` text and icon color.

![Screenshot 2023-07-31 at 17 17 25](https://github.com/flutter/flutter/assets/48603081/288cf892-5b51-4365-9855-5ef0ed2928e9)
2023-08-10 16:05:03 +00:00
Taha Tesser
bb6b72d6c6
Fix DropdownButtonFormField input border clipping (#131481)
fixes [BUG: DropdownButtonFormField input decorator focus/hover is not clipped
](https://github.com/flutter/flutter/issues/131282)

### Description

This fixes an issue where `DropdownButtonFormField`'s input border isn't used for clipping with `InkWell`.

### Before
![Screenshot 2023-07-28 at 17 06 20](https://github.com/flutter/flutter/assets/48603081/8fe1ee1f-5cea-4297-b4f6-e672d74bb583)

### After
![Screenshot 2023-07-28 at 17 06 38](https://github.com/flutter/flutter/assets/48603081/a0091459-67dc-45ca-96b1-95d7093d475f)
2023-08-10 08:36:17 +00:00
Kate Lovett
0c80ed6d12
Keep alive support for 2D scrolling (#131641)
Fixes https://github.com/flutter/flutter/issues/126297

This adds support for keep alive to the 2D scrolling foundation. The TwoDimensionalChildBuilderDelegate and TwoDimensionalChildListDelegate will both add automatic keep alives to their children, matching the convention from SliverChildDelegates. The TwoDimensionalViewportParentData now incorporates keep alive and which is managed by the RenderTwoDimensionalViewport.
2023-08-10 05:46:05 +00:00
LongCatIsLooong
9156f6b5f3
Add missing ignore: deprecated_member_use to unblock the engine roller (#132280)
## Pre-launch Checklist

- [ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ ] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [ ] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
2023-08-09 22:00:05 -07:00
Sam Rawlins
9a32f24a34
Fix prefer_null_aware_operators violation (#132242)
Use a null-aware `?.` operator instead of a conditional operator. This complies with the `prefer_null_aware_operators` rule. Fixes https://github.com/flutter/flutter/issues/132241

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
2023-08-10 03:08:11 +00:00
LongCatIsLooong
3f831b694f
Making TextPainter rounding hack disabled by default (#132094)
Migrate tests in flutter/flutter. Once the tests here and in `*_customer_testing` are migrated, the default value of the migration flag will be changed from false to true, making the rounding hack disabled by default.
2023-08-10 00:30:52 +00:00
Ian Hickson
9c8f3950e3
Sample code for ImageProvider (#131952)
Also:
- minor improvements to documentation
- wrap one of our test error messages in a manner more consistent with other messages
2023-08-09 22:58:26 +00:00
Bernardo Ferrari
6da6fbf5a8
Deprecate describeEnum. (#125016)
Final part of https://github.com/flutter/flutter/issues/123346.
2023-08-09 21:58:52 +00:00
Justin McCandless
f5ceaf9810
Handle hasStrings on web (#132093)
By default, Flutter web uses the browser's built-in context menu.

<img width="200" src="https://github.com/flutter/flutter/assets/389558/990f99cb-bc38-40f1-9e88-8839bc342da5" />

As of [recently](https://github.com/flutter/engine/pull/38682), it's possible to use a Flutter-rendered context menu like the other platforms.

```dart
void main() {
  runApp(const MyApp());
  BrowserContextMenu.disableContextMenu();
}
```

But there is a bug (https://github.com/flutter/flutter/issues/129692) that the Paste button is missing and never shows up.

<img width="284" alt="Screenshot 2023-08-07 at 2 39 03 PM" src="https://github.com/flutter/flutter/assets/389558/f632be25-28b1-4e2e-98f7-3bb443f077df">

The reason why it's missing is that Flutter first checks if there is any pasteable text on the clipboard before deciding to show the Paste button using the `hasStrings` platform channel method, but that was never implemented for web ([original hasStrings PR](https://github.com/flutter/flutter/pull/87678)).

So let's just implement hasStrings for web?  No, because Chrome shows a permissions prompt when the clipboard is accessed, and there is [no browser clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API) to avoid it.  The prompt will show immediately when the EditableText is built, not just when the Paste button is pressed.

<img width="200" src="https://github.com/flutter/flutter/assets/389558/5abdb160-1b13-4f1a-87e1-4653ca19d73e" />

### This PR's solution

Instead, before implementing hasStrings for web, this PR disables the hasStrings check for web.  The result is that users will always see a paste button, even in the (unlikely) case that they have nothing pasteable on the clipboard.  However, they will not see a permissions dialog until they actually click the Paste button.  Subsequent pastes don't show the permission dialog.

<details>

<summary>Video of final behavior with this PR</summary>

https://github.com/flutter/flutter/assets/389558/ed16c925-8111-44a7-99e8-35a09d682748

</details>

I think this will be the desired behavior for the vast majority of app developers.  Those that want different behavior can use hasStrings themselves, which will be implemented in https://github.com/flutter/engine/pull/43360.

### References

Fixes https://github.com/flutter/flutter/issues/129692
Engine PR to be merged after this: https://github.com/flutter/engine/pull/43360
2023-08-09 20:36:45 +00:00
Renzo Olivares
6ac161f909
Add an example for TapAndPanGestureRecognizer (#131873)
This adds an example for `TapAndPanGestureRecognizer` that demonstrates how to scale a widget using a double tap + vertical drag gesture.

https://github.com/flutter/flutter/assets/948037/4c6c5467-2157-4b6a-bc52-264a3b6303de
2023-08-09 19:59:03 +00:00
Mouad Debbar
632681da99
Reland "[web] Migrate framework to fully use package:web (#128901)" (#132092)
Relanding https://github.com/flutter/flutter/pull/128901

Part of https://github.com/flutter/flutter/issues/113402
Part of https://github.com/flutter/flutter/issues/127030
2023-08-09 19:41:45 +00:00
LongCatIsLooong
aac018974f
Use pattern matching to avoid strange type annotations (#131964)
Addresses https://github.com/flutter/flutter/pull/131640#discussion_r1284861384
2023-08-09 04:43:57 +00:00
LongCatIsLooong
5de6684b9c
Add more info to OverlayState.insert error messages (#129363)
I was debugging an Overlay issue and felt I could have identified the problem faster if the existing assertions provided more information about the current state of the OverlayEntry and Overlay.
2023-08-09 00:53:10 +00:00
Qun Cheng
0bc5a2bca4
Add textCapitalization property for SearchBar and SearchAnchor (#131459)
This is to add `textCapitalization` property for `SearchBar` and `SearchAnchor`.
Fixes: #131260
2023-08-08 23:24:19 +00:00
Jesús S Guerrero
2728ba0f23
Revert of #120385 (#132167)
Breaking google testing 
revert of: https://github.com/flutter/flutter/pull/120385
b/295065534
2023-08-08 16:16:52 -07:00
Taha Tesser
b77b149df6
Add PopupMenuButton.iconColor, PopupMenuTheme.iconSize and fix button icon using unexpected color propert (#132054)
fixes [PopupMenuButton uses color property for icon color](https://github.com/flutter/flutter/issues/127802) 
fixes [`popup_menu_test.dart` lacks default icon color tests.](https://github.com/flutter/flutter/issues/132050) 

### Description
- Add  `PopupMenuButton..iconColor` and fix the PopupMenu button icon using an unexpected color property.
- Add the missing `PopupMenuTheme.iconSize`.
- Clean up some tests and minor improvements.

### Code sample

<details> 
<summary>expand to view the code sample</summary> 

```dart
import 'package:flutter/material.dart';

/// Flutter code sample for [PopupMenuButton].

// This is the type used by the popup menu below.
enum SampleItem { itemOne, itemTwo, itemThree }

void main() => runApp(const PopupMenuApp());

class PopupMenuApp extends StatelessWidget {
  const PopupMenuApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        popupMenuTheme: PopupMenuThemeData(
          // iconSize: 75,
          // iconColor: Colors.amber,
          color: Colors.deepPurple[100],
        ),
      ),
      home: const PopupMenuExample(),
    );
  }
}

class PopupMenuExample extends StatefulWidget {
  const PopupMenuExample({super.key});

  @override
  State<PopupMenuExample> createState() => _PopupMenuExampleState();
}

class _PopupMenuExampleState extends State<PopupMenuExample> {
  SampleItem? selectedMenu;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('PopupMenuButton')),
      body: Center(
        child: PopupMenuButton<SampleItem>(
          iconSize: 75,
          // iconColor: Colors.amber,
          color: Colors.deepPurple[100],
          initialValue: selectedMenu,
          // Callback that sets the selected popup menu item.
          onSelected: (SampleItem item) {
            setState(() {
              selectedMenu = item;
            });
          },
          itemBuilder: (BuildContext context) => <PopupMenuEntry<SampleItem>>[
            const PopupMenuItem<SampleItem>(
              value: SampleItem.itemOne,
              child: Text('Item 1'),
            ),
            const PopupMenuItem<SampleItem>(
              value: SampleItem.itemTwo,
              child: Text('Item 2'),
            ),
            const PopupMenuDivider(),
            const CheckedPopupMenuItem<SampleItem>(
              value: SampleItem.itemThree,
              checked: true,
              child: Text('Item 3'),
            ),
          ],
        ),
      ),
    );
  }
}

``` 
	
</details>

![Group 2](https://github.com/flutter/flutter/assets/48603081/eb5404ae-2a07-4374-9821-66a0bbea041e)

![Group 1](https://github.com/flutter/flutter/assets/48603081/464e3957-1afb-4118-abcc-aad12591dc51)
2023-08-08 22:23:30 +00:00
Ian Hickson
e65c37ee45
More PageStorage clarity in the documentation (#131954)
Fixes https://github.com/flutter/flutter/issues/10867
2023-08-08 22:08:32 +00:00
Taha Tesser
ee47267d26
Fix TabBarTheme.indicatorColor not applied in Material 2 (#132123)
fixes [[Proposal] Improve TabBarTheme styling API for indicator color ](https://github.com/flutter/flutter/issues/130392)

### Description

This fixes an issue where the `TabBarTheme.indicator` isn't applied in Material 2 and also adds indicator color tests for both M3 and M2.

### Code sample

<details> 
<summary>expand to view the code sample</summary> 

```dart
import 'package:flutter/material.dart';

/// Flutter code sample for [TabBar].

void main() => runApp(const TabBarApp());

class TabBarApp extends StatelessWidget {
  const TabBarApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        useMaterial3: false,
        tabBarTheme: const TabBarTheme(
          indicatorColor: Colors.amber,
        )
      ),
      home: const TabBarExample(),
    );
  }
}

class TabBarExample extends StatelessWidget {
  const TabBarExample({super.key});

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      initialIndex: 1,
      length: 3,
      child: Scaffold(
        appBar: AppBar(
          title: const Text('TabBar Sample'),
          bottom: const TabBar(
            tabs: <Widget>[
              Tab(
                icon: Icon(Icons.cloud_outlined),
                text: 'Cloudy',
              ),
              Tab(
                icon: Icon(Icons.beach_access_sharp),
                text: 'Sunny',
              ),
              Tab(
                icon: Icon(Icons.brightness_5_sharp),
                text: 'Rainy',
              ),
            ],
          ),
        ),
        body: const TabBarView(
          children: <Widget>[
            Center(
              child: Text("It's cloudy here"),
            ),
            Center(
              child: Text("It's rainy here"),
            ),
            Center(
              child: Text("It's sunny here"),
            ),
          ],
        ),
      ),
    );
  }
}
``` 
	
</details>

### Before
![Screenshot 2023-08-08 at 15 39 24](https://github.com/flutter/flutter/assets/48603081/9030e025-8615-45d0-a337-87ba2fdf6ca3)

### After
![Screenshot 2023-08-08 at 15 39 07](https://github.com/flutter/flutter/assets/48603081/4b98ac55-2d51-4a4c-93ba-7d36dc4be1d8)
2023-08-08 19:37:16 +00:00
Aakash Pamnani
0b81347897
Paginated Data Table : Fixed Row number at footer in last page (#130389)
Fixed the row count in the footer.

Before
![image](https://github.com/flutter/flutter/assets/76067278/2365b85f-d896-4cea-a5b3-f043970bec98)

After
![image](https://github.com/flutter/flutter/assets/76067278/69b18ecb-a3c9-44ea-961f-b4073ee0384d)

*Issues Resolved*
Fixes #80421
2023-08-08 19:25:53 +00:00
LouiseHsu
d9cb50e63d
[framework] Add Search Web to selection controls for iOS (#131898)
This PR adds framework support for the Search Web feature in iOS. 

https://github.com/flutter/flutter/assets/36148254/c159f0d9-8f14-45e7-b295-e065b0826fab

The corresponding merged engine PR can be found [here](https://github.com/flutter/engine/pull/43324).
This PR addresses https://github.com/flutter/flutter/issues/82907 
More details are available in this [design doc](https://docs.google.com/document/d/1QizXwBiO-2REIcEovl5pK06BaLPOWYmNwOE5jactJZA/edit?resourcekey=0-1pb9mJiAq29Gesmt25GAug)
2023-08-08 17:34:17 +00:00
Justin McCandless
9655311545
Remove Iterator from _History (#132101)
Cleaning up private code in Navigator.
2023-08-08 10:25:27 -07:00
Ian Hickson
9dbd1e9872
More documentation about warm-up frames (#132085) 2023-08-08 17:11:15 +00:00
Jesús S Guerrero
cef00d0c53
Revert "Replace TextField.canRequestFocus with TextField.focusNode.canRequestFocus" (#132104)
Reverts flutter/flutter#130164

reverting because it cause internal google testing failures b/294917394
2023-08-07 17:30:07 -07:00
chunhtai
b01cb301cf
Adds more documentations around ignoreSemantics deprecations. (#131287)
migration guide update https://github.com/flutter/website/pull/9124

fixes the concerns in https://github.com/flutter/flutter/pull/120619
2023-08-07 23:59:48 +00:00
Mouad Debbar
55fe41be59
[web] New HtmlElementView.fromTagName constructor (#130513)
This wraps up the platform view improvements discussed in https://github.com/flutter/flutter/issues/127030.

- Splits `HtmlElementView` into 2 files that are conditionally imported.
- The non-web version can be instantiated but it throws if it ends up being built in a widget tree.
- Out-of-the-box view factories that create visible & invisible DOM elements given a `tagName` parameter.
- New `HtmlElementView.fromTagName()` constructor that uses the default factories to create DOM elements.
- Tests covering the new API.

Depends on https://github.com/flutter/engine/pull/43828

Fixes https://github.com/flutter/flutter/issues/127030
2023-08-07 23:45:19 +00:00
Justin McCandless
ebbb4b3887
Android context menu theming and visual update (#131816)
Fixes https://github.com/flutter/flutter/issues/89939 and updates the look of the Android context menu to match API 34.

## The problem
Before this PR, setting `surface` in the color scheme caused the background color of the Android context menu to change, but it wasn't possible to change the text color.

```dart
MaterialApp(
  theme: ThemeData(
    // Using a dark theme made the context menu text color be white.
    colorScheme: ThemeData.dark().colorScheme.copyWith(
      // Setting the surface here worked.
      surface: Colors.white,
      // But there was no way to set the text color. This didn't work.
      onSurface: Colors.black,
    ),
  ),
),
```

| Expected (after PR) | Actual (before PR) |
| --- | --- |
| <img width="239" alt="Screenshot 2023-08-07 at 11 45 37 AM" src="https://github.com/flutter/flutter/assets/389558/a9fb75e5-b6c3-4f8e-8c59-2021780c44a7"> | <img width="250" alt="Screenshot 2023-08-07 at 11 51 10 AM" src="https://github.com/flutter/flutter/assets/389558/a5abd2d2-49bb-47a0-836f-864d56af2f58"> |

## Other examples

<table>
<tr>
<th>Scenario</th>
<th>Result</th>
</tr>
<tr>
<td>

```dart
MaterialApp(
  theme: ThemeData(
    colorScheme: ThemeData.light(),
  ),
  ...
),
```

</td>
<td>
<img width="244" alt="Screenshot 2023-08-07 at 11 42 05 AM" src="https://github.com/flutter/flutter/assets/389558/74c6870b-5ff7-4b1a-9e0c-b2bb4809ef1e">
</td>
</tr>
<tr>
<td>

```dart
MaterialApp(
  theme: ThemeData(
    colorScheme: ThemeData.dark(),
  ),
  ...
),
```

</td>
<td>
<img width="239" alt="Screenshot 2023-08-07 at 11 42 23 AM" src="https://github.com/flutter/flutter/assets/389558/91fe32f8-bd62-4d9b-96e8-ae5a9a769745">
</td>
</tr>
<tr>
<td>

```dart
MaterialApp(
  theme: ThemeData(
    colorScheme: ThemeData.light().colorScheme.copyWith(
      surface: Colors.blue,
      onSurface: Colors.red,
    ),
  ),
  ...
),
```

</td>
<td>
<img width="240" alt="Screenshot 2023-08-07 at 11 43 06 AM" src="https://github.com/flutter/flutter/assets/389558/e5752f8b-3738-4391-9055-15c38bd4af21">
</td>
</tr>
<tr>
<td>

```dart
MaterialApp(
  theme: ThemeData(
    colorScheme: ThemeData.light().colorScheme.copyWith(
      surface: Colors.blue,
      onSurface: Colors.red,
    ),
  ),
  ...
),
```

</td>
<td>
<img width="244" alt="Screenshot 2023-08-07 at 11 42 47 AM" src="https://github.com/flutter/flutter/assets/389558/68cc68f0-b338-4d94-8810-d8e46fb1e48e">
</td>
</tr>
</table>
2023-08-07 20:59:08 +00:00
xhzq233
ff5b0e1457
CupertinoContextMenu improvement (#131030)
Fixes overlapping gestures in CupertinoContextMenu's subtree
2023-08-07 09:30:21 -07:00
Mingyu
06ca902dfc
Slider should check mounted before start interaction (#132010)
This is a follow up to the following pull requests:
- https://github.com/flutter/flutter/pull/124514

I was finally able to reproduce this bug and found out why it was happening. Consider this code:

```dart
GestureDetector(
  behavior: HitTestBehavior.translucent,
  // Note: Make sure onTap is not null to ensure events
  // are captured by `GestureDetector`
  onTap: () {},
  child: _shouldShowSlider
    ? Slider(value: _value, onChanged: _handleSlide)
    : const SizedBox.shrink().
)
```

Runtime exception happens when:

1. User taps and holds the Slider (drag callback captured by `GestureDetector`)
2. `_shouldShowSlider` changes to false, Slider disappears and unmounts, and unregisters `_handleSlide`. But the callback is still registered by `GestureDetector`
3. Users moves finger as if Slider were still there
4. Drag callback is invoked, `_SliderState.showValueIndicator` is called
5. Exception - Slider is already disposed

This pull request fixes it by adding a mounted check inside `_SliderState.showValueIndicator` to ensure the Slider is actually mounted at the time of invoking drag event callback. I've added a unit test that will fail without this change.

The error stack trace is:

```
The following assertion was thrown while handling a gesture:
This widget has been unmounted, so the State no longer has a context (and should be considered
defunct).
Consider canceling any active work during "dispose" or using the "mounted" getter to determine if
the State is still active.

When the exception was thrown, this was the stack:
#0      State.context.<anonymous closure> (package:flutter/src/widgets/framework.dart:950:9)
#1      State.context (package:flutter/src/widgets/framework.dart:956:6)
#2      _SliderState.showValueIndicator (package:flutter/src/material/slider.dart:968:18)
#3      _RenderSlider._startInteraction (package:flutter/src/material/slider.dart:1487:12)
#4      _RenderSlider._handleDragStart (package:flutter/src/material/slider.dart:1541:5)
#5      DragGestureRecognizer._checkStart.<anonymous closure> (package:flutter/src/gestures/monodrag.dart:531:53)
#6      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:275:24)
#7      DragGestureRecognizer._checkStart (package:flutter/src/gestures/monodrag.dart:531:7)
#8      DragGestureRecognizer._checkDrag (package:flutter/src/gestures/monodrag.dart:498:5)
#9      DragGestureRecognizer.acceptGesture (package:flutter/src/gestures/monodrag.dart:431:7)
#10     _CombiningGestureArenaMember.acceptGesture (package:flutter/src/gestures/team.dart:45:14)
#11     GestureArenaManager._resolveInFavorOf (package:flutter/src/gestures/arena.dart:281:12)
#12     GestureArenaManager._resolve (package:flutter/src/gestures/arena.dart:239:9)
#13     GestureArenaEntry.resolve (package:flutter/src/gestures/arena.dart:53:12)
#14     _CombiningGestureArenaMember._resolve (package:flutter/src/gestures/team.dart:85:15)
#15     _CombiningGestureArenaEntry.resolve (package:flutter/src/gestures/team.dart:19:15)
#16     OneSequenceGestureRecognizer.resolve (package:flutter/src/gestures/recognizer.dart:375:13)
#17     DragGestureRecognizer.handleEvent (package:flutter/src/gestures/monodrag.dart:414:13)
#18     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:98:12)
#19     PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:143:9)
#20     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:625:13)
#21     PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:141:18)
#22     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:127:7)
#23     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:488:19)
#24     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:468:22)
#25     RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:439:11)
#26     GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:413:7)
#27     GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:376:5)
#28     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:323:7)
#29     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:292:9)
#30     _invoke1 (dart:ui/hooks.dart:186:13)
#31     PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:433:7)
#32     _dispatchPointerDataPacket (dart:ui/hooks.dart:119:31)

Handler: "onStart"
Recognizer:
  HorizontalDragGestureRecognizer#a5df2
```

*List which issues are fixed by this PR. You must list at least one issue.*

Internal bug: b/273666179, b/192329942

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
2023-08-07 16:03:23 +00:00
Tomasz Gucio
55044a605f
Constrain _RenderScaledInlineWidget child size in computeDryLayout (#131765) 2023-08-07 10:28:07 +02:00
Tomasz Gucio
bc4cacac0d
Take paint offset into account for inline children hit test in Editable (#131675) 2023-08-05 15:36:54 +02:00
Polina Cherkasova
d5f8ca7281
Add TODO to refactor error handling. (#131878) 2023-08-05 01:28:03 +00:00
Justin McCandless
dedd100ebd
Predictive back support for root routes (#120385)
This PR aims to support Android's predictive back gesture when popping the entire Flutter app.  Predictive route transitions between routes inside of a Flutter app will come later.

<img width="200" src="https://user-images.githubusercontent.com/389558/217918109-945febaa-9086-41cc-a476-1a189c7831d8.gif" />

### Trying it out

If you want to try this feature yourself, here are the necessary steps:

  1. Run Android 33 or above.
  1. Enable the feature flag for predictive back on the device under "Developer
     options".
  1. Create a Flutter project, or clone [my example project](https://github.com/justinmc/flutter_predictive_back_examples).
  1. Set `android:enableOnBackInvokedCallback="true"` in
     android/app/src/main/AndroidManifest.xml (already done in the example project).
  1. Check out this branch.
  1. Run the app. Perform a back gesture (swipe from the left side of the
     screen).

You should see the predictive back animation like in the animation above and be able to commit or cancel it.

### go_router support

go_router works with predictive back out of the box because it uses a Navigator internally that dispatches NavigationNotifications!

~~go_router can be supported by adding a listener to the router and updating SystemNavigator.setFrameworkHandlesBack.~~

Similar to with nested Navigators, nested go_routers is supported by using a PopScope widget.

<details>

<summary>Full example of nested go_routers</summary>

```dart
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:go_router/go_router.dart';

import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';

void main() => runApp(_MyApp());

class _MyApp extends StatelessWidget {
  final GoRouter router = GoRouter(
    routes: <RouteBase>[
      GoRoute(
        path: '/',
        builder: (BuildContext context, GoRouterState state) => _HomePage(),
      ),
      GoRoute(
        path: '/nested_navigators',
        builder: (BuildContext context, GoRouterState state) => _NestedGoRoutersPage(),
      ),
    ],
  );

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerConfig: router,
    );
  }
}

class _HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Nested Navigators Example'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text('Home Page'),
            const Text('A system back gesture here will exit the app.'),
            const SizedBox(height: 20.0),
            ListTile(
              title: const Text('Nested go_router route'),
              subtitle: const Text('This route has another go_router in addition to the one used with MaterialApp above.'),
              onTap: () {
                context.push('/nested_navigators');
              },
            ),
          ],
        ),
      ),
    );
  }
}

class _NestedGoRoutersPage extends StatefulWidget {
  @override
  State<_NestedGoRoutersPage> createState() => _NestedGoRoutersPageState();
}

class _NestedGoRoutersPageState extends State<_NestedGoRoutersPage> {
  late final GoRouter _router;
  final GlobalKey<NavigatorState> _nestedNavigatorKey = GlobalKey<NavigatorState>();

  // If the nested navigator has routes that can be popped, then we want to
  // block the root navigator from handling the pop so that the nested navigator
  // can handle it instead.
  bool get _popEnabled {
    // canPop will throw an error if called before build. Is this the best way
    // to avoid that?
    return _nestedNavigatorKey.currentState == null ? true : !_router.canPop();
  }

  void _onRouterChanged() {
    // Here the _router reports the location correctly, but canPop is still out
    // of date.  Hence the post frame callback.
    SchedulerBinding.instance.addPostFrameCallback((Duration duration) {
      setState(() {});
    });
  }

  @override
  void initState() {
    super.initState();

    final BuildContext rootContext = context;
    _router = GoRouter(
      navigatorKey: _nestedNavigatorKey,
      routes: [
        GoRoute(
          path: '/',
          builder: (BuildContext context, GoRouterState state) => _LinksPage(
            title: 'Nested once - home route',
            backgroundColor: Colors.indigo,
            onBack: () {
              rootContext.pop();
            },
            buttons: <Widget>[
              TextButton(
                onPressed: () {
                  context.push('/two');
                },
                child: const Text('Go to another route in this nested Navigator'),
              ),
            ],
          ),
        ),
        GoRoute(
          path: '/two',
          builder: (BuildContext context, GoRouterState state) => _LinksPage(
            backgroundColor: Colors.indigo.withBlue(255),
            title: 'Nested once - page two',
          ),
        ),
      ],
    );

    _router.addListener(_onRouterChanged);
  }

  @override
  void dispose() {
    _router.removeListener(_onRouterChanged);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return PopScope(
      popEnabled: _popEnabled,
      onPopped: (bool success) {
        if (success) {
          return;
        }
        _router.pop();
      },
      child: Router<Object>.withConfig(
        restorationScopeId: 'router-2',
        config: _router,
      ),
    );
  }
}

class _LinksPage extends StatelessWidget {
  const _LinksPage ({
    required this.backgroundColor,
    this.buttons = const <Widget>[],
    this.onBack,
    required this.title,
  });

  final Color backgroundColor;
  final List<Widget> buttons;
  final VoidCallback? onBack;
  final String title;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: backgroundColor,
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(title),
            //const Text('A system back here will go back to Nested Navigators Page One'),
            ...buttons,
            TextButton(
              onPressed: onBack ?? () {
                context.pop();
              },
              child: const Text('Go back'),
            ),
          ],
        ),
      ),
    );
  }
}
```

</details>

### Resources

Fixes https://github.com/flutter/flutter/issues/109513
Depends on engine PR https://github.com/flutter/engine/pull/39208 ✔️ 
Design doc: https://docs.google.com/document/d/1BGCWy1_LRrXEB6qeqTAKlk-U2CZlKJ5xI97g45U7azk/edit#
Migration guide: https://github.com/flutter/website/pull/8952
2023-08-04 20:44:44 +00:00
Taha Tesser
05f9a96ea4
Mention showTimePicker function be can be used to show dialog with the time picker in the TimePickerDialog docs (#131932)
fixes https://github.com/flutter/flutter/issues/131931

Every time I search for the time picker in the API docs I end up in the `TimePickerDialog` docs.  

We should link `showTimePicker` so it can be easier to reach it and mention it can be used directly to show a dialog with a time picker.
2023-08-04 17:38:07 +00:00
Kate Lovett
b3a4decda6
Assert against infinite values of control points in CatmullRomSpline (#131820)
When providing infinite values for the control points of CatmullRomSpline, a StackOverflowError occurs. This asserts against that and provides a helpful error message. 

Fixes https://github.com/flutter/flutter/issues/131246
2023-08-03 00:18:13 +00:00
Polina Cherkasova
0ad45f2421
Update stack_frame.dart to parse unexpected error format to null. (#131786)
Fixes https://github.com/flutter/flutter/issues/131627

Originally this code sometimes was returning null and sometimes was failing, when stack frame is in unexpected format.

This PR updates for one of the code paths from failing to returning null.
2023-08-02 23:57:15 +00:00