Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
7c22f0d2
Unverified
Commit
7c22f0d2
authored
Jan 28, 2021
by
Darshan Rander
Committed by
GitHub
Jan 28, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added warning when not enabled platform is selected (#73205)
parent
669795bc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
128 additions
and
4 deletions
+128
-4
create.dart
packages/flutter_tools/lib/src/commands/create.dart
+59
-4
create_test.dart
...tter_tools/test/commands.shard/permeable/create_test.dart
+69
-0
No files found.
packages/flutter_tools/lib/src/commands/create.dart
View file @
7c22f0d2
...
...
@@ -300,13 +300,19 @@ class CreateCommand extends CreateBase {
}
else
if
(
_getSupportedPlatformsInPlugin
(
projectDir
).
isEmpty
){
_printNoPluginMessage
();
}
_printAddPlatformMessage
(
relativePluginPath
);
final
List
<
String
>
platformsToWarn
=
_getPlatformWarningList
(
requestedPlatforms
);
if
(
platformsToWarn
.
isNotEmpty
)
{
_printWarningDisabledPlatform
(
platformsToWarn
);
}
_printPluginAddPlatformMessage
(
relativePluginPath
);
}
else
{
// Tell the user the next steps.
final
FlutterProject
project
=
FlutterProject
.
fromPath
(
projectDirPath
);
final
FlutterProject
app
=
project
.
hasExampleApp
?
project
.
example
:
project
;
final
String
relativeAppPath
=
globals
.
fs
.
path
.
normalize
(
globals
.
fs
.
path
.
relative
(
app
.
directory
.
path
));
final
String
relativeAppMain
=
globals
.
fs
.
path
.
join
(
relativeAppPath
,
'lib'
,
'main.dart'
);
final
List
<
String
>
requestedPlatforms
=
_getUserRequestedPlatforms
();
// Let them know a summary of the state of their tooling.
globals
.
printStatus
(
'''
...
...
@@ -322,7 +328,13 @@ To enable null safety, type:
Your
$application
code is in
$relativeAppMain
.
'''
);
// Show warning if any selected platform is not enabled
final
List
<
String
>
platformsToWarn
=
_getPlatformWarningList
(
requestedPlatforms
);
if
(
platformsToWarn
.
isNotEmpty
)
{
_printWarningDisabledPlatform
(
platformsToWarn
);
}
}
return
FlutterCommandResult
.
success
();
}
...
...
@@ -500,21 +512,64 @@ To edit platform code in an IDE see https://flutter.dev/developing-packages/#edi
void
_printPluginUpdatePubspecMessage
(
String
pluginPath
,
String
platformsString
)
{
globals
.
printStatus
(
'''
You need to update
$pluginPath
/pubspec.yaml to support
$platformsString
.
'''
,
emphasis:
true
,
color:
TerminalColor
.
red
);
}
void
_printNoPluginMessage
(
)
{
globals
.
printError
(
'''
You'
ve
created
a
plugin
project
that
doesn
't yet support any platforms.
'''
);
}
void
_printAddPlatformMessage
(
String
pluginPath
)
{
void
_print
Plugin
AddPlatformMessage
(
String
pluginPath
)
{
globals
.
printStatus
(
'''
To add platforms, run `flutter create -t plugin --platforms <platforms> .` under
$pluginPath
.
For more information, see https://flutter.dev/go/plugin-platforms.
'''
);
}
// returns a list disabled, but requested platforms
List
<
String
>
_getPlatformWarningList
(
List
<
String
>
requestedPlatforms
)
{
final
List
<
String
>
platformsToWarn
=
<
String
>[
if
(
requestedPlatforms
.
contains
(
'web'
)
&&
!
featureFlags
.
isWebEnabled
)
'web'
,
if
(
requestedPlatforms
.
contains
(
'macos'
)
&&
!
featureFlags
.
isMacOSEnabled
)
'macos'
,
if
(
requestedPlatforms
.
contains
(
'windows'
)
&&
!
featureFlags
.
isWindowsEnabled
)
'windows'
,
if
(
requestedPlatforms
.
contains
(
'linux'
)
&&
!
featureFlags
.
isLinuxEnabled
)
'linux'
,
];
return
platformsToWarn
;
}
void
_printWarningDisabledPlatform
(
List
<
String
>
platforms
)
{
final
List
<
String
>
desktop
=
<
String
>[];
final
List
<
String
>
web
=
<
String
>[];
for
(
final
String
platform
in
platforms
)
{
if
(
platform
==
'web'
)
{
web
.
add
(
platform
);
}
else
if
(
platform
==
'macos'
||
platform
==
'windows'
||
platform
==
'linux'
)
{
desktop
.
add
(
platform
);
}
}
if
(
desktop
.
isNotEmpty
)
{
final
String
platforms
=
desktop
.
length
>
1
?
'platforms'
:
'platform'
;
final
String
verb
=
desktop
.
length
>
1
?
'are'
:
'is'
;
globals
.
printStatus
(
'''
The desktop
$platforms
:
${desktop.join(', ')}
$verb
currently not supported on your local environment.
For more details, see: https://flutter.dev/desktop
'''
);
}
if
(
web
.
isNotEmpty
)
{
globals
.
printStatus
(
'''
The web is currently not supported on your local environment.
For more details, see: https://flutter.dev/docs/get-started/web
'''
);
}
}
packages/flutter_tools/test/commands.shard/permeable/create_test.dart
View file @
7c22f0d2
...
...
@@ -37,6 +37,7 @@ import '../../src/testbed.dart';
const
String
_kNoPlatformsMessage
=
'You
\'
ve created a plugin project that doesn
\'
t yet support any platforms.
\n
'
;
const
String
frameworkRevision
=
'12345678'
;
const
String
frameworkChannel
=
'omega'
;
const
String
_kDisabledPlatformRequestedMessage
=
'currently not supported on your local environment.'
;
// TODO(fujino): replace FakePlatform.fromPlatform() with FakePlatform()
final
Generator
_kNoColorTerminalPlatform
=
()
=>
FakePlatform
.
fromPlatform
(
const
LocalPlatform
())..
stdoutSupportsAnsi
=
false
;
final
Map
<
Type
,
Generator
>
noColorTerminalOverride
=
<
Type
,
Generator
>{
...
...
@@ -2352,6 +2353,74 @@ void main() {
Logger:
()
=>
logger
,
});
testUsingContext
(
'should show warning when disabled platforms are selected while creating a plugin'
,
()
async
{
Cache
.
flutterRoot
=
'../..'
;
when
(
mockFlutterVersion
.
frameworkRevision
).
thenReturn
(
frameworkRevision
);
when
(
mockFlutterVersion
.
channel
).
thenReturn
(
frameworkChannel
);
final
CreateCommand
command
=
CreateCommand
();
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
command
);
await
runner
.
run
(<
String
>[
'create'
,
'--no-pub'
,
'--template=plugin'
,
'--platforms=android,ios,web,windows,macos,linux'
,
projectDir
.
path
]);
await
runner
.
run
(<
String
>[
'create'
,
'--no-pub'
,
'--template=plugin'
,
projectDir
.
path
]);
expect
(
logger
.
statusText
,
contains
(
_kDisabledPlatformRequestedMessage
));
},
overrides:
<
Type
,
Generator
>{
FeatureFlags:
()
=>
TestFeatureFlags
(),
Logger:
()
=>
logger
,
});
testUsingContext
(
"shouldn't show warning when only enabled platforms are selected while creating a plugin"
,
()
async
{
Cache
.
flutterRoot
=
'../..'
;
when
(
mockFlutterVersion
.
frameworkRevision
).
thenReturn
(
frameworkRevision
);
when
(
mockFlutterVersion
.
channel
).
thenReturn
(
frameworkChannel
);
final
CreateCommand
command
=
CreateCommand
();
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
command
);
await
runner
.
run
(<
String
>[
'create'
,
'--no-pub'
,
'--template=plugin'
,
'--platforms=android,ios,windows'
,
projectDir
.
path
]);
await
runner
.
run
(<
String
>[
'create'
,
'--no-pub'
,
'--template=plugin'
,
projectDir
.
path
]);
expect
(
logger
.
statusText
,
isNot
(
contains
(
_kDisabledPlatformRequestedMessage
)));
},
overrides:
<
Type
,
Generator
>{
FeatureFlags:
()
=>
TestFeatureFlags
(
isWindowsEnabled:
true
),
Logger:
()
=>
logger
,
});
testUsingContext
(
'should show warning when disabled platforms are selected while creating a app'
,
()
async
{
Cache
.
flutterRoot
=
'../..'
;
when
(
mockFlutterVersion
.
frameworkRevision
).
thenReturn
(
frameworkRevision
);
when
(
mockFlutterVersion
.
channel
).
thenReturn
(
frameworkChannel
);
final
CreateCommand
command
=
CreateCommand
();
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
command
);
await
runner
.
run
(<
String
>[
'create'
,
'--no-pub'
,
'--platforms=android,ios,web,windows,macos,linux'
,
projectDir
.
path
]);
await
runner
.
run
(<
String
>[
'create'
,
'--no-pub'
,
projectDir
.
path
]);
expect
(
logger
.
statusText
,
contains
(
_kDisabledPlatformRequestedMessage
));
},
overrides:
<
Type
,
Generator
>{
FeatureFlags:
()
=>
TestFeatureFlags
(),
Logger:
()
=>
logger
,
});
testUsingContext
(
"shouldn't show warning when only enabled platforms are selected while creating a app"
,
()
async
{
Cache
.
flutterRoot
=
'../..'
;
when
(
mockFlutterVersion
.
frameworkRevision
).
thenReturn
(
frameworkRevision
);
when
(
mockFlutterVersion
.
channel
).
thenReturn
(
frameworkChannel
);
final
CreateCommand
command
=
CreateCommand
();
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
command
);
await
runner
.
run
(<
String
>[
'create'
,
'--no-pub'
,
'--template=plugin'
,
'--platforms=windows'
,
projectDir
.
path
]);
await
runner
.
run
(<
String
>[
'create'
,
'--no-pub'
,
'--template=plugin'
,
projectDir
.
path
]);
expect
(
logger
.
statusText
,
isNot
(
contains
(
_kDisabledPlatformRequestedMessage
)));
},
overrides:
<
Type
,
Generator
>{
FeatureFlags:
()
=>
TestFeatureFlags
(
isWindowsEnabled:
true
,
isAndroidEnabled:
false
,
isIOSEnabled:
false
),
Logger:
()
=>
logger
,
});
testUsingContext
(
'flutter create prints note about null safety'
,
()
async
{
await
_createProject
(
projectDir
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment